summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/xkiller.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-09-11 18:24:28 +0200
committertv <tv@krebsco.de>2023-09-13 18:07:11 +0200
commit0c4f3acb281be6290c55a6e96bc29fab5b5c7a11 (patch)
treedadaec00477a095273475ac345b2066b4748c399 /pkgs/simple/xkiller.nix
parentab1d0479e90f11806d4703ec6fffed3d5f782914 (diff)
stockholm -> hrm
Diffstat (limited to 'pkgs/simple/xkiller.nix')
-rw-r--r--pkgs/simple/xkiller.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkgs/simple/xkiller.nix b/pkgs/simple/xkiller.nix
new file mode 100644
index 0000000..8d8f016
--- /dev/null
+++ b/pkgs/simple/xkiller.nix
@@ -0,0 +1,25 @@
+{ pkgs }:
+pkgs.writeDash "xkiller" ''
+ set -efu
+ exec >&2
+ ${pkgs.iproute}/bin/ss -lp src unix:/tmp/.X11-unix/X* |
+ ${pkgs.gnused}/bin/sed -n '
+ s|.*/tmp/.X11-unix/X\([0-9]\+\)\>.*("X[^"]*",pid=\([0-9]\+\)\>.*|\1 \2|p
+ ' |
+ while read -r display pid; do
+ {
+ exit_code=$(
+ DISPLAY=:$display ${pkgs.coreutils}/bin/timeout 1 \
+ ${pkgs.xorg.xset}/bin/xset q >/dev/null 2>&1 &&
+ echo 0 || echo $?
+ )
+ if test $exit_code = 124; then
+ echo "X on display :$display is locked up; killing PID $pid..."
+ ${pkgs.coreutils}/bin/kill -SIGKILL "$pid"
+ else
+ echo "X on display :$display is healthy"
+ fi
+ } &
+ done
+ wait
+''