From 042288d6eba04099c7b832521f01af0a7e5eb6c6 Mon Sep 17 00:00:00 2001 From: James Myers Date: Wed, 21 Oct 2026 00:40:16 -0700 Subject: [PATCH 1/3] End the input-device watch and pactl subscribe with the shell Quickshell does not take its Process children along when it stops. The clipboard watchers already start under setpriv --pdeathsig TERM; the inotifywait in Commons/InputDevices.qml and the pactl subscribe in Commons/UntypedInput.qml did not, so each shell restart or crash left them running under init. A quiet /dev/input gives the orphaned inotifywait no event to fail a write on, so it stays until logout. Co-Authored-By: Claude Sonnet 5.5 --- shell/Commons/InputDevices.qml | 5 ++++- shell/Commons/UntypedInput.qml | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/Commons/InputDevices.qml b/shell/Commons/InputDevices.qml index fa008264368f..90cf90ba0061 100644 --- a/shell/Commons/InputDevices.qml +++ b/shell/Commons/InputDevices.qml @@ -34,9 +34,12 @@ Singleton { // again after it went away with the last device, when the watch on the old // directory is gone and has to be set up on the new one. udev's records for // input devices are the c13: entries, character major 13. + // setpriv ends the watch with the shell: Quickshell does not take its + // children along when it stops, and a quiet /dev/input never makes the + // orphaned inotifywait notice. Process { id: watcher - command: ["bash", "-c", + command: ["setpriv", "--pdeathsig", "TERM", "bash", "-c", "dirs=(\"$2\"); for dir in \"$1\" \"$3\"; do [[ -d $dir ]] && dirs+=(\"$dir\"); done; " + "exec inotifywait -m -q -e create,delete,delete_self,moved_to --format '%w|%e|%f' \"${dirs[@]}\"", "input-devices", root.inputDir, root.devDir, root.udevDir] diff --git a/shell/Commons/UntypedInput.qml b/shell/Commons/UntypedInput.qml index f7dfd9365fd4..762b8e6e4eb0 100644 --- a/shell/Commons/UntypedInput.qml +++ b/shell/Commons/UntypedInput.qml @@ -124,10 +124,11 @@ Singleton { } // The volume keys, the mute key and other apps change the node too. pactl - // translates its events, so they are read in the C locale. + // translates its events, so they are read in the C locale. setpriv ends it + // with the shell, which does not take its children along when it stops. Process { id: events - command: ["pactl", "subscribe"] + command: ["setpriv", "--pdeathsig", "TERM", "pactl", "subscribe"] environment: ({ LC_ALL: "C" }) onRunningChanged: if (running) root.subscribedAt = Date.now() onExited: { From 8c6a9f165f1066bb2b6f522a416b638433564627 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Thu, 22 Oct 2026 04:07:56 +0200 Subject: [PATCH 2/3] Say which stops the pdeathsig comments cover A clean stop already kills these children: omarchy-restart-shell's quickshell kill reaps the old inotifywait on a worker, as Quickshell's Process destructor does. Only a shell that dies without running it (SIGKILL, Qt's _exit on a lost Wayland connection) orphans them, which is what setpriv covers, so the comments no longer say Quickshell never takes its children along. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex Medium --- shell/Commons/InputDevices.qml | 5 ++--- shell/Commons/UntypedInput.qml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/shell/Commons/InputDevices.qml b/shell/Commons/InputDevices.qml index 90cf90ba0061..1fb274645fb3 100644 --- a/shell/Commons/InputDevices.qml +++ b/shell/Commons/InputDevices.qml @@ -34,9 +34,8 @@ Singleton { // again after it went away with the last device, when the watch on the old // directory is gone and has to be set up on the new one. udev's records for // input devices are the c13: entries, character major 13. - // setpriv ends the watch with the shell: Quickshell does not take its - // children along when it stops, and a quiet /dev/input never makes the - // orphaned inotifywait notice. + // setpriv ends the watch if the shell is killed rather than stopped: a quiet + // /dev/input never makes an orphaned inotifywait notice. Process { id: watcher command: ["setpriv", "--pdeathsig", "TERM", "bash", "-c", diff --git a/shell/Commons/UntypedInput.qml b/shell/Commons/UntypedInput.qml index 762b8e6e4eb0..7c44d576614a 100644 --- a/shell/Commons/UntypedInput.qml +++ b/shell/Commons/UntypedInput.qml @@ -125,7 +125,7 @@ Singleton { // The volume keys, the mute key and other apps change the node too. pactl // translates its events, so they are read in the C locale. setpriv ends it - // with the shell, which does not take its children along when it stops. + // if the shell is killed rather than stopped. Process { id: events command: ["setpriv", "--pdeathsig", "TERM", "pactl", "subscribe"] From 1a6f1cd19ddbccf1b1e55aec0984aa5cc1a1634f Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:06:36 +0100 Subject: [PATCH 3/3] Cover killed-shell watcher cleanup Bring the behavioral SIGKILL regression from #19283 into the older fix so a watcher surviving its shell cannot silently return. Keep the fixture's explicit child cleanup independent of the guard it tests, including when an earlier assertion fails. Co-Authored-By: Alex Muresan Co-Authored-By: GPT-6 High Co-Authored-By: Opus 5.5 High --- test/shell.d/input-devices-test.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/shell.d/input-devices-test.sh b/test/shell.d/input-devices-test.sh index 5f6097b4a352..d6ab187642ad 100755 --- a/test/shell.d/input-devices-test.sh +++ b/test/shell.d/input-devices-test.sh @@ -15,8 +15,8 @@ require_command inotifywait stage=$(mktemp -d) QS_PID="" -# Quickshell restarts a watcher killed under it, and leaves one running when it -# is stopped itself, so stop the shell first and then what it had started. +# Stop the shell before its children so its restart timer cannot replace them; +# clean up explicitly even when the parent-death guard regresses. stop_shell() { local children=() @@ -173,6 +173,28 @@ wait_changes $(( before + 1 )) || fail "the seat is read again once a lost watch (( $(changes) > before )) || fail "the seat is read again once a lost watch is back" "$(cat "$stage/log")" pass "the seat is read again once a lost watch is back" +# A killed shell cannot clean up its watcher. Each orphan holds an inotify +# instance, so relaunches must not accumulate them. +watch_pid="" +for _ in {1..50}; do + watch_pid=$(pgrep -P "$QS_PID" -f "inotifywait .*$stage/root/dev/input" || true) + [[ -n $watch_pid ]] && break + sleep 0.1 +done +[[ -n $watch_pid ]] || fail "the watch is up before the shell is killed" "$(cat "$stage/log")" +kill -KILL "$QS_PID" +wait "$QS_PID" 2>/dev/null || true +QS_PID="" +for _ in {1..20}; do + kill -0 "$watch_pid" 2>/dev/null || break + sleep 0.1 +done +if kill -0 "$watch_pid" 2>/dev/null; then + kill "$watch_pid" 2>/dev/null || true + fail "a killed shell takes its watch with it" "inotifywait $watch_pid outlived the shell" +fi +pass "a killed shell takes its watch with it" + # A watch that cannot be set up at all (no /dev here, an exhausted inotify # limit on a real machine) keeps failing at once. Its retries must not each # make every bar ask Hyprland: past the first reading, the keyboard widget's