diff options
author | tv <tv@krebsco.de> | 2019-01-07 15:29:48 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2019-01-07 15:29:48 +0100 |
commit | e0bbedff27bd3ca6d69b147f2f3dbc183de72243 (patch) | |
tree | 291af92f0276f9eda0293b87e6498a014f4cad80 /tv | |
parent | 7c84b32f2de5c759f18fe449597e0edba493ad9d (diff) |
tv xkiller: init
Diffstat (limited to 'tv')
-rw-r--r-- | tv/5pkgs/simple/xkiller.nix | 25 |
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 000000000..8d8f01690 --- /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 +'' |