summaryrefslogtreecommitdiff
path: root/src/ioslay-mgr.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/ioslay-mgr.sh')
-rwxr-xr-xsrc/ioslay-mgr.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/ioslay-mgr.sh b/src/ioslay-mgr.sh
new file mode 100755
index 0000000..56ab849
--- /dev/null
+++ b/src/ioslay-mgr.sh
@@ -0,0 +1,105 @@
1#!/bin/bash
2
3UNIT_NAME=ioslay
4if [ "$1" = launch-unit ]
5then
6 if systemctl --user is-active "$UNIT_NAME"
7 then systemctl --user restart "$UNIT_NAME"
8 else systemd-run --user -u "$UNIT_NAME" "$0"
9 fi
10 exit
11fi
12
13if [ -e /usr/lib/bash/sleep ]
14then
15 enable -f /usr/lib/bash/sleep sleep
16fi
17
18export NOTICE=y
19noticeLOG() { [ "$NOTICE" ] || return; echo "Notice: $*" >&2; }
20debugLOG() { [ "$DBG" ] || return; echo "Debug: $*" >&2; }
21
22. sliceweasel.lib.sh
23
24vkill()
25{
26 if [ $# = 0 ]
27 then
28 return
29 fi
30 (
31 if [ "$(id -u)" = 0 ]
32 then sudo=
33 else sudo=sudo
34 fi
35 set -x
36 ps u "$@"
37 $sudo kill "$@"
38 )
39}
40
41slay_slayer()
42{
43 if [ "$ioslay" ]
44 then
45 children=$(for pid in $ioslay; do pgrep -P $ioslay; done)
46 grandchildren=$(for pid in $children; do pgrep -P $pid; done)
47 vkill $ioslay $children $grandchildren
48 fi
49}
50
51GROUP_BASENAME=firefox
52
53group_procs=$(get_firefox_cgroup_procs)
54
55ioslay=
56lastprocs=
57SIGNALLED=
58trap 'SIGNALLED=y' SIGINT SIGTERM SIGHUP
59while [ ! "$SIGNALLED" ]
60do
61 if ! [ -e "$group_procs" ]
62 then
63 [ "$warned" ] || echo "Warning: firefox not running or cgroup not found" >&2
64 warned=y
65 else
66 if [ "$warned" ]
67 then
68 echo "Found firefox cgroup: $group_procs" >&2
69 warned=
70 fi
71 read -N 1000100 procs < "$group_procs"
72 if [ "$procs" ]
73 then
74 set --
75 for pid in $procs
76 do
77 read comm < /proc/$pid/comm
78 case "$comm" in
79 'Isolated Web Content' | 'Web Content' | 'Isolated Web Co')
80 set -- "$@" "$pid"
81 debugLOG "accept /proc/$pid/comm $comm"
82 ;;
83 *)
84 debugLOG "reject /proc/$pid/comm $comm"
85 esac
86 done
87
88 # echo "pids: ($*|$(echo $procs))" >&2
89 if [ "$lastargs" != "$*" ]
90 then
91 slay_slayer
92 wait $ioslay
93 if [ $# -gt 0 ]
94 then
95 ioslay-firefox "$@" &
96 ioslay=$!
97 noticeLOG "Launched ioslay-firefox[$ioslay] $*"
98 fi
99 fi
100 lastargs=$*
101 fi
102 fi
103 sleep 1
104done
105slay_slayer