summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-03-28 01:15:29 -0400
committerAndrew Cady <d@cryptonomic.net>2022-03-28 01:15:29 -0400
commit4718994c2de95aefdc6a9a272da2e874fff41a79 (patch)
tree7ac62e50936f023bac703328341d3c1a6fdba3bc
parent27ec0712a4bdc8e27cab768ef407ab632f4261b9 (diff)
cleanup; uid detection works
-rwxr-xr-xfireslay2
-rwxr-xr-xioslay-firefox46
-rwxr-xr-xioslay-mgr.sh67
-rwxr-xr-xsliceweasel.lib.sh14
4 files changed, 36 insertions, 93 deletions
diff --git a/fireslay b/fireslay
index 9485cd4..ef1e4f4 100755
--- a/fireslay
+++ b/fireslay
@@ -83,7 +83,7 @@ web_content_pids()
83 done < $FIREFOX_GROUP_PROCS 83 done < $FIREFOX_GROUP_PROCS
84} 84}
85 85
86uid=$(getent passwd $SUDO_USER | (IFS=: read _ _ id _; echo $id)) 86uid=$(get_uid)
87group=user.slice/user-$uid.slice/firefox 87group=user.slice/user-$uid.slice/firefox
88group_procs=/sys/fs/cgroup/$group/cgroup.procs 88group_procs=/sys/fs/cgroup/$group/cgroup.procs
89 89
diff --git a/ioslay-firefox b/ioslay-firefox
index fb382e0..5041260 100755
--- a/ioslay-firefox
+++ b/ioslay-firefox
@@ -69,40 +69,14 @@ iotop_reader()
69 done 69 done
70} 70}
71 71
72if [ "$UID" != 0 ] 72sudo_iotop()
73then 73{
74 sudo -- "$0" "$@" 74 if [ "$UID" = 0 ]
75 exit 75 then
76fi 76 command iotop "$@"
77 77 else
78while [ $# -gt 0 ] 78 sudo iotop "$@"
79do 79 fi
80 case "$1" in 80}
81 -q | --quiet )
82 exec 2>/dev/null
83 shift
84 ;;
85 -a | --all )
86 IOSLAY_KILL_ALL=y
87 shift
88 ;;
89 -- )
90 shift
91 break
92 ;;
93 -* )
94 exit 1
95 ;;
96 * )
97 break
98 ;;
99 esac
100done
101
102# if [ $# -gt 0 ]
103# then
104# echo "$0: Error: usage" >&2
105# exit 1
106# fi
107 81
108iotop -qq -b $(printf '\55\55pid=%s\n' "$@") | iotop_reader 82sudo_iotop -qq -b $(printf '\55\55pid=%s\n' "$@") | iotop_reader
diff --git a/ioslay-mgr.sh b/ioslay-mgr.sh
index 85ff4d7..423aa5e 100755
--- a/ioslay-mgr.sh
+++ b/ioslay-mgr.sh
@@ -1,58 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2 2
3ioslay= 3. sliceweasel.lib.sh
4each_new_process()
5{
6 while read pid _
7 do
8 read -N 10001000 procs < /sys/fs/cgroup/$group/cgroup.procs
9 set -- $procs
10
11 for pid in "$@"
12 do
13 if read comm < /proc/$pid/comm && [ "$comm" = 'Web Content' ]
14 then
15 set -- "$@" "$1"
16 fi
17 shift
18 done
19
20 if [ "$ioslay" ]
21 then
22 children=$(pgrep -P $ioslay)
23 if [ "$children" ]
24 then
25 kill $children
26 fi
27 wait $ioslay
28 fi
29
30 if [ $# -gt 0 ]
31 then
32 ioslay-firefox "$@" &
33 ioslay=$!
34 fi
35 done
36}
37
38get_uid()
39{
40 (
41 if [ "$SUDO_USER" ]
42 then
43 IFS=:
44 set -- $(getent passwd "${SUDO_USER}") || return
45 echo $3
46 else
47 id -un
48 fi
49 )
50}
51
52#cgroup-show-each-new-process "$group" | grep --line-buffered 'Web Content' | each_new_process
53
54# Really, could just check for any/first cgroup with processes and basename
55# 'firefox'. Fork for each one.
56 4
57vkill() 5vkill()
58{ 6{
@@ -61,9 +9,13 @@ vkill()
61 return 9 return
62 fi 10 fi
63 ( 11 (
12 if [ "$(id -u)" = 0 ]
13 then sudo=
14 else sudo=sudo
15 fi
64 set -x 16 set -x
65 ps u "$@" 17 ps u "$@"
66 sudo kill "$@" 18 $sudo kill "$@"
67 ) 19 )
68} 20}
69 21
@@ -77,8 +29,11 @@ slay_slayer()
77 fi 29 fi
78} 30}
79 31
32GROUP_BASENAME=firefox
33
34uid=$(set -x; get_uid)
80uid=1000 35uid=1000
81group=user.slice/user-$uid.slice/firefox 36group=user.slice/user-$uid.slice/$GROUP_BASENAME
82group_procs=/sys/fs/cgroup/$group/cgroup.procs 37group_procs=/sys/fs/cgroup/$group/cgroup.procs
83wantcomm='Web Content' 38wantcomm='Web Content'
84ioslay= 39ioslay=
@@ -105,7 +60,7 @@ do
105 then 60 then
106 slay_slayer 61 slay_slayer
107 wait $ioslay 62 wait $ioslay
108 sudo ioslay-firefox "$@" & 63 ioslay-firefox "$@" &
109 ioslay=$! 64 ioslay=$!
110 fi 65 fi
111 lastargs=$* 66 lastargs=$*
diff --git a/sliceweasel.lib.sh b/sliceweasel.lib.sh
index 890fb79..28091a0 100755
--- a/sliceweasel.lib.sh
+++ b/sliceweasel.lib.sh
@@ -120,6 +120,20 @@ set_max_ratio()
120 esac 120 esac
121} 121}
122 122
123get_uid()
124{
125 (
126 if [ "$SUDO_USER" ]
127 then
128 IFS=:
129 set -- $(getent passwd "${SUDO_USER}") || return
130 echo $3
131 else
132 id -u
133 fi
134 )
135}
136
123get_current_group() 137get_current_group()
124{ 138{
125 read g < /proc/$$/cgroup 139 read g < /proc/$$/cgroup