diff options
author | lassulus <lassulus@lassul.us> | 2019-01-16 11:17:20 +0100 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2019-01-16 11:17:20 +0100 |
commit | 879b6d319a18dce6e5f686c997643c78229469a8 (patch) | |
tree | c21b0eef944b80adecb7d95aa79ba4a475ef6dd1 /tv/5pkgs/simple/xkiller.nix | |
parent | a1d9c22bbd8eff9198f378e9007ddf4cb9ee2e5c (diff) | |
parent | 2d2ab95f0707209c4c248d43cb57877a50a37991 (diff) |
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'tv/5pkgs/simple/xkiller.nix')
-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 +'' |