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