Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion shell/Commons/InputDevices.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ 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 if the shell is killed rather than stopped: a quiet
// /dev/input never makes an 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]
Expand Down
5 changes: 3 additions & 2 deletions shell/Commons/UntypedInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
// if the shell is killed rather than stopped.
Process {
id: events
command: ["pactl", "subscribe"]
command: ["setpriv", "--pdeathsig", "TERM", "pactl", "subscribe"]
environment: ({ LC_ALL: "C" })
onRunningChanged: if (running) root.subscribedAt = Date.now()
onExited: {
Expand Down
26 changes: 24 additions & 2 deletions test/shell.d/input-devices-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=()

Expand Down Expand Up @@ -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
Expand Down
Loading