summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-28 21:54:34 -0400
committerDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-28 21:54:34 -0400
commitc04b7b520a03ee020fa658c502b185a5a9857301 (patch)
tree9e163a7d4c2e3c5d6bd61932b8f1b42cd65f58eb /src
parentb00a5efe39bf1195ef0c8037093df2604afa911d (diff)
Remove all obsolete files
Perhaps these are not all completely obsolete; some might serve as starting points for unimplemented features. In particular, 'fireslay' may be useful, and also 'your-fired.sh', but these are not in working order. (They worked at one point, but major changes in the other parts of this code base should have broken them.) Hopefully, this commit message will be enough to locate them if ever required!
Diffstat (limited to 'src')
-rwxr-xr-xsrc/cgroup-show-each-new-process51
-rwxr-xr-xsrc/firefox-io-slayer105
-rw-r--r--[-rwxr-xr-x]src/firefox@.service.in0
-rwxr-xr-xsrc/fireslay38
-rwxr-xr-xsrc/slice47
-rwxr-xr-xsrc/sliceuser13
-rwxr-xr-xsrc/sliceweasel15
-rw-r--r--src/your-fired.sh136
8 files changed, 0 insertions, 405 deletions
diff --git a/src/cgroup-show-each-new-process b/src/cgroup-show-each-new-process
deleted file mode 100755
index d1473f1..0000000
--- a/src/cgroup-show-each-new-process
+++ /dev/null
@@ -1,51 +0,0 @@
1#!/bin/bash
2cgroup=${1:-firefox~$(id -u)}
3
4show_new_pids()
5{
6 if [ -e "$procs" ]
7 then
8 sort < "$procs" > pids
9 if [ -e old-pids ]
10 then
11 comm -13 old-pids pids
12 else
13 cat pids
14 fi
15 mv pids old-pids
16 fi
17}
18
19show_pid_comm()
20{
21 local pid comm
22 pid=$1
23 if 2>/dev/null read comm < /proc/$pid/comm
24 then
25 echo "$pid $comm"
26 else
27 echo $pid '(disappeared)' >&2
28 fi
29}
30
31each_line()
32{
33 local line
34 while read line
35 do "$@" "$line"
36 done
37}
38
39RUNTIME_DIR=$(mktemp -d) || exit
40trap 'cd /; rm -rf "$RUNTIME_DIR"' EXIT
41cd "$RUNTIME_DIR"
42
43enable -f /usr/lib/bash/sleep sleep
44procs=/sys/fs/cgroup/$cgroup/cgroup.procs
45
46while true
47do
48 show_new_pids
49 sleep 1
50done | each_line show_pid_comm
51
diff --git a/src/firefox-io-slayer b/src/firefox-io-slayer
deleted file mode 100755
index 56ab849..0000000
--- a/src/firefox-io-slayer
+++ /dev/null
@@ -1,105 +0,0 @@
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
diff --git a/src/firefox@.service.in b/src/firefox@.service.in
index e3c0329..e3c0329 100755..100644
--- a/src/firefox@.service.in
+++ b/src/firefox@.service.in
diff --git a/src/fireslay b/src/fireslay
deleted file mode 100755
index 3c68ad5..0000000
--- a/src/fireslay
+++ /dev/null
@@ -1,38 +0,0 @@
1#!/bin/sh
2set -e
3. sliceweasel.lib.sh
4
5is_web_content()
6{
7 local comm state
8 read comm < /proc/"$1"/comm && [ "$comm" = 'Web Content' ] &&
9 read _ _ state _ < /proc/"$1"/stat && [ "$state" != Z ] || return
10}
11
12web_content_pids()
13{
14 while read pid
15 do
16 if is_web_content $pid
17 then
18 echo $pid
19 fi
20 done < $FIREFOX_GROUP_PROCS
21}
22
23FIREFOX_GROUP_PROCS=$(get_firefox_cgroup_procs)
24
25[ -e "$FIREFOX_GROUP_PROCS" ] || die "Firefox group not found ($FIREFOX_GROUP_PROCS)"
26
27set -- $(web_content_pids)
28
29if [ $# = 0 ]
30then
31 exit
32fi
33
34(
35 set -x
36 ps $* >&2
37 kill $*
38)
diff --git a/src/slice b/src/slice
deleted file mode 100755
index 44ae13e..0000000
--- a/src/slice
+++ /dev/null
@@ -1,47 +0,0 @@
1#!/bin/bash
2default_percent='50'
3keep_env=(XAUTHORITY DISPLAY)
4set -e
5
6usage()
7{
8 cat <<EOF
9Usage: $0 [percentage]% [--] command [arguments...]
10
11 The [percentage] argument must end with a literal '%'.
12
13 E.g.:
14
15 slice 50% firefox
16
17 The command cannot start with a literal '-'.
18EOF
19}
20
21percent=$1
22case "$1" in
23 --) percent=$default_percent ;;
24 '' | -*) usage >&2; exit 1;;
25 *.*%) percent=${1%.*} ;;
26 *%) percent=${1%\%} ;;
27esac
28[ "$percent" -ge 0 ]
29[ "$percent" -le 100 ]
30
31shift
32case "$1" in
33 --) shift ;;
34esac
35unit_name=$1
36
37keep_env_opts=()
38for v in "${keep_env[@]}"
39do
40 keep_env_opts+=(-E "${!v}")
41done
42
43systemd-run -u "$unit_name" \
44 "${keep_env_opts[@]}"
45 "$0" "$@"
46 "$@"
47
diff --git a/src/sliceuser b/src/sliceuser
deleted file mode 100755
index 16d441f..0000000
--- a/src/sliceuser
+++ /dev/null
@@ -1,13 +0,0 @@
1#!/bin/sh
2. sliceweasel.lib.sh
3
4set -e
5IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
6[ -d "$IO_ROOT_DIR" ]
7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --'
8
9group=$(get_current_group)
10set -x
11set_max_ratio "$group" memory 3/4
12set_max_ratio "$group" io 8/10
13
diff --git a/src/sliceweasel b/src/sliceweasel
deleted file mode 100755
index f9df2c8..0000000
--- a/src/sliceweasel
+++ /dev/null
@@ -1,15 +0,0 @@
1#!/bin/sh
2. sliceweasel.lib.sh
3
4set -e
5IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
6[ -d "$IO_ROOT_DIR" ]
7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --'
8
9group=/sys/fs/cgroup/user.slice/user-$(id -u).slice/firefox
10join_group "$group"
11set_max_ratio "$group" memory 1/2
12set_max_ratio "$group" io 7/10
13exec firefox "$@"
14
15
diff --git a/src/your-fired.sh b/src/your-fired.sh
deleted file mode 100644
index 59efaf7..0000000
--- a/src/your-fired.sh
+++ /dev/null
@@ -1,136 +0,0 @@
1#!/bin/bash
2
3WEB_CONTENT_OOM_ADJ=500
4FIREFIX_REPEAT_INTERVAL=5
5
6ploop()
7{
8 local p
9 for p in /proc/[0-9]*
10 do
11 "$@"
12 done
13}
14
15match_parent()
16{
17 # This isn't a file to which we will write (we write to the child's
18 # oom_score_adj), but this ignores processes we don't own.
19 2>/dev/null [ -w "$p"/oom_score_adj ] || return
20
21 local stat
22 2>/dev/null read stat < "$p"/stat || return
23 case "$stat" in
24 *") "?" $1 "*) echo "${p##*/}" ;;
25 esac
26}
27
28match_comm()
29{
30 local comm
31 2>/dev/null read comm < "$p"/comm || return
32 [ "$comm" = "$1" ] && echo "${p##*/}"
33}
34
35firefix()
36{
37 parent=$1
38 read parent_oom_score < /proc/$parent/oom_score
39 read parent_oom_score_adj < /proc/$parent/oom_score_adj
40
41 for child in $(ploop match_parent $parent)
42 do
43 2>/dev/null read comm < /proc/$child/comm || continue
44 [ "$comm" = 'Web Content' ] || continue
45
46 read oom_score < /proc/$child/oom_score
47 read oom_score_adj < /proc/$child/oom_score_adj
48
49 want_adj=$((parent_oom_score_adj + ${WEB_CONTENT_OOM_ADJ:-500}))
50 if [ "$want_adj" -gt "$oom_score_adj" ]
51 then
52 printf 'Setting oom_score_adj for pid=%d to %d (from %d)\n' $child $want_adj $oom_score_adj >&2
53 printf '%d\n' "$want_adj" > /proc/$child/oom_score_adj
54 fi
55 done
56}
57
58firefix_all()
59{
60 for parent in $(ploop match_comm firefox-bin)
61 do
62 firefix $parent &
63 done
64 wait
65}
66
67firefix_all_forever()
68{
69 while true
70 do
71 firefix_all
72 sleep ${FIREFIX_REPEAT_INTERVAL:-5}
73 done
74}
75
76unit_file()
77{
78 cat <<EOF
79[Unit]
80Description=$1
81[Service]
82ExecStart=$2
83[Install]
84WantedBy=default.target
85EOF
86}
87
88install_self()
89{
90 unit_file_name=$1
91 unit_executable=$2
92 unit_args=$3
93 unit_desc=$4
94
95 [ -e "$unit_executable" ] || return
96
97 if [ "$(id -u)" = 0 ]
98 then
99 service_dir=/etc/systemd/system
100 systemctl=systemctl
101 instdir=/usr/local/bin
102 else
103 service_dir=$HOME/.config/systemd/user
104 systemctl='systemctl --user'
105 instdir=$HOME/.local/bin
106 fi
107 unit_executable_installed=$instdir/${unit_executable##*/}
108
109 [ "$unit_executable_installed" -ef "$unit_executable" ] ||
110 install -D -t "$instdir" "$unit_executable" || return
111
112 [ -d "$service_dir" ] || mkdir -p "$service_dir" || return
113
114 unit_file=${service_dir}/${unit_file_name}.service
115 unit_file "$unit_desc" "$unit_executable_installed $unit_args" > "$unit_file"
116
117 $systemctl daemon-reload
118 $systemctl enable "$unit_file_name"
119 $systemctl restart "$unit_file_name"
120 $systemctl status "$unit_file_name"
121}
122
123usage()
124{
125 echo "Usage: $0 <install|once|forever>" >&2
126}
127
128enable -f /usr/lib/bash/sleep sleep 2>/dev/null || true
129
130case "$*" in
131 forever) firefix_all_forever ;;
132 install) install_self firefixer "$0" forever 'Firefixer - adjust firefox OOM scores';;
133 once) firefix_all ;;
134 -h|--help) usage; exit ;;
135 *) usage; exit 1 ;;
136esac