summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs/simple/xkiller.nix
diff options
context:
space:
mode:
authorjeschli <jeschli@gmail.com>2019-01-29 19:17:43 +0100
committerjeschli <jeschli@gmail.com>2019-01-29 19:17:43 +0100
commit92f5e7ef0e7a4d44932d9a0207db06624cf6d3fe (patch)
tree63476fd9540895458bf0f0bb9b05951444c3e2b4 /tv/5pkgs/simple/xkiller.nix
parent5630c40e3d30e3b1bb92a4852d7b462420bb05af (diff)
parenta10178e5e7afb819a211a94f306bd8f029677bb6 (diff)
Merge branch 'master' of prism.r:stockholm
Diffstat (limited to 'tv/5pkgs/simple/xkiller.nix')
-rw-r--r--tv/5pkgs/simple/xkiller.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/tv/5pkgs/simple/xkiller.nix b/tv/5pkgs/simple/xkiller.nix
new file mode 100644
index 0000000..8d8f016
--- /dev/null
+++ b/tv/5pkgs/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
+''