Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
Fix infinite spin on a value-less flag in the menu scripts
`shift 2` is a no-op when only one positional parameter remains, so a
trailing `-x`/`-y`/`-i`/`-a` with no value left `$1` unchanged and the
`while [[ $# -gt 0 ]]` loop spun at 100% CPU forever. Eight orphaned
cce-desktop-menu processes had been pinning eight cores for ~29 minutes
each after a malformed invocation.
Guard each flag on having a value present; a dangling flag now consumes
itself and is dropped rather than being forwarded to cce-cloud as a bare
`-x`/`-y`.
Co-Authored-By: Claude Fable 5 <[email protected]>
scripts/cce-app-menu | 14 ++++++--------
scripts/cce-desktop-menu | 8 ++++----
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/scripts/cce-app-menu b/scripts/cce-app-menu
index de594e6..70d39b2 100644
--- a/scripts/cce-app-menu
+++ b/scripts/cce-app-menu
@@ -13,20 +13,18 @@ app_id=""
while [[ $# -gt 0 ]]; do
case "$1" in
-x|--x-pos)
- x_arg="-x $2"
- shift 2
+ # A flag with no value must still consume itself: bare `shift 2`
+ # is a no-op when one arg remains, and the loop spins forever.
+ if [[ $# -ge 2 ]]; then x_arg="-x $2"; shift 2; else shift; fi
;;
-y|--y-pos)
- y_arg="-y $2"
- shift 2
+ if [[ $# -ge 2 ]]; then y_arg="-y $2"; shift 2; else shift; fi
;;
-i|--window-id)
- window_index="$2"
- shift 2
+ if [[ $# -ge 2 ]]; then window_index="$2"; shift 2; else shift; fi
;;
-a|--app-id)
- app_id="$2"
- shift 2
+ if [[ $# -ge 2 ]]; then app_id="$2"; shift 2; else shift; fi
;;
*)
shift
diff --git a/scripts/cce-desktop-menu b/scripts/cce-desktop-menu
index 1098618..59e5fb9 100644
--- a/scripts/cce-desktop-menu
+++ b/scripts/cce-desktop-menu
@@ -11,12 +11,12 @@ y_arg=""
while [[ $# -gt 0 ]]; do
case "$1" in
-x|--x-pos)
- x_arg="-x $2"
- shift 2
+ # A flag with no value must still consume itself: bare `shift 2`
+ # is a no-op when one arg remains, and the loop spins forever.
+ if [[ $# -ge 2 ]]; then x_arg="-x $2"; shift 2; else shift; fi
;;
-y|--y-pos)
- y_arg="-y $2"
- shift 2
+ if [[ $# -ge 2 ]]; then y_arg="-y $2"; shift 2; else shift; fi
;;
*)
shift