From 80d567dfdeb86b1de9daf1c34c60b2b52e0e234a Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:18:54 +0100 Subject: [PATCH] killall and pgrep updates. Set --ns $$ on commands. --- .../plugins/dynamix.docker.manager/scripts/dockerupdate | 2 +- emhttp/plugins/dynamix.plugin.manager/Plugins.page | 2 +- emhttp/plugins/dynamix/DashStats.page | 2 +- emhttp/plugins/dynamix/Eth0.page | 4 ++-- emhttp/plugins/dynamix/include/FileSystemStatus.php | 6 +++--- emhttp/plugins/dynamix/include/Helpers.php | 4 ++-- emhttp/plugins/dynamix/include/OpenTerminal.php | 4 ++-- emhttp/plugins/dynamix/include/StartCommand.php | 2 +- emhttp/plugins/dynamix/scripts/reiserfs_check | 2 +- etc/rc.d/rc.K | 2 +- etc/rc.d/rc.acpid | 2 +- etc/rc.d/rc.bind | 2 +- etc/rc.d/rc.dnsmasq | 2 +- etc/rc.d/rc.elogind | 2 +- etc/rc.d/rc.inetd | 2 +- etc/rc.d/rc.mcelog | 2 +- etc/rc.d/rc.messagebus | 4 ++-- etc/rc.d/rc.nfsd | 8 ++++---- etc/rc.d/rc.ntpd | 4 ++-- etc/rc.d/rc.rpc | 8 ++++---- etc/rc.d/rc.samba | 2 +- etc/rc.d/rc.smartd | 2 +- etc/rc.d/rc.udev | 2 +- etc/rc.d/rc.wsdd2 | 2 +- sbin/mover | 2 +- 25 files changed, 38 insertions(+), 38 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate b/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate index 592e3fc00..33002a6e4 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate +++ b/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate @@ -24,7 +24,7 @@ $_SERVER['REQUEST_URI'] = "scripts"; $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; -exec("pgrep docker", $pid); +exec('pgrep --ns $$ docker', $pid); if (count($pid) == 1) exit(0); $DockerClient = new DockerClient(); diff --git a/emhttp/plugins/dynamix.plugin.manager/Plugins.page b/emhttp/plugins/dynamix.plugin.manager/Plugins.page index 99c85d2c5..66ccdb768 100644 --- a/emhttp/plugins/dynamix.plugin.manager/Plugins.page +++ b/emhttp/plugins/dynamix.plugin.manager/Plugins.page @@ -19,7 +19,7 @@ Code="e944" ?> /dev/null")!='folder' ? _('Docker vdisk') : _('Docker folder'); $dot = _var($display,'number','.,')[0]; $zfs = count(array_filter(array_column($disks,'fsType'),function($fs){return str_replace('luks:','',$fs??'')=='zfs';})); diff --git a/emhttp/plugins/dynamix/Eth0.page b/emhttp/plugins/dynamix/Eth0.page index 1d614fec2..c7f1de5f9 100644 --- a/emhttp/plugins/dynamix/Eth0.page +++ b/emhttp/plugins/dynamix/Eth0.page @@ -60,8 +60,8 @@ foreach ($ports as $ethX) { } } // enable interface only when VMs and Docker are stopped -$service = exec("pgrep libvirt") ? _('VM manager') : ''; -$service .= exec("pgrep docker") ? ($service ? ' '._('and').' ' : '')._('Docker service') : ''; +$service = exec('pgrep --ns $$ libvirt') ? _('VM manager') : ''; +$service .= exec('pgrep --ns $$ docker') ? ($service ? ' '._('and').' ' : '')._('Docker service') : ''; // eth0 port status $no_eth0 = exec("ip link show eth0|grep -Pom1 '(NO-CARRIER|state DOWN)'"); diff --git a/emhttp/plugins/dynamix/include/FileSystemStatus.php b/emhttp/plugins/dynamix/include/FileSystemStatus.php index 0342a4f4e..2901f3524 100644 --- a/emhttp/plugins/dynamix/include/FileSystemStatus.php +++ b/emhttp/plugins/dynamix/include/FileSystemStatus.php @@ -40,9 +40,9 @@ default: $file = "/var/lib/$dir/check.status.$id"; if (file_exists($file)) { switch ($cmd) { - case 'btrfs-check': $pgrep = "pgrep -f '/sbin/btrfs check .*$dev'"; break; - case 'rfs-check': $pgrep = "pgrep -f '/sbin/reiserfsck $dev'"; break; - case 'xfs-check': $pgrep = "pgrep -f '/sbin/xfs_repair.*$dev'"; break; + case 'btrfs-check': $pgrep = 'pgrep --ns \$\$ -f '."'/sbin/btrfs check .*$dev'"; break; + case 'rfs-check': $pgrep = 'pgrep --ns $$ -f '."'/sbin/reiserfsck $dev'"; break; + case 'xfs-check': $pgrep = 'pgrep --ns $$ -f '."'/sbin/xfs_repair.*$dev'"; break; } echo file_get_contents($file); if (!exec($pgrep)) echo "\0"; diff --git a/emhttp/plugins/dynamix/include/Helpers.php b/emhttp/plugins/dynamix/include/Helpers.php index f64ba2f2d..6908d526b 100644 --- a/emhttp/plugins/dynamix/include/Helpers.php +++ b/emhttp/plugins/dynamix/include/Helpers.php @@ -263,7 +263,7 @@ function urlencode_path($path) { return str_replace("%2F", "/", urlencode($path)); } function pgrep($process_name, $escape_arg=true) { - $pid = exec("pgrep ".($escape_arg?escapeshellarg($process_name):$process_name), $output, $retval); + $pid = exec('pgrep --ns $$ '.($escape_arg?escapeshellarg($process_name):$process_name), $output, $retval); return $retval==0 ? $pid : false; } function is_block($path) { @@ -372,7 +372,7 @@ function my_rmdir($dirname) { 'dataset' => $zfsdataset, 'type' => $fstype, 'cmd' => $cmdstr, - 'error' => $error, + 'error' => ]; break; case "btrfs": diff --git a/emhttp/plugins/dynamix/include/OpenTerminal.php b/emhttp/plugins/dynamix/include/OpenTerminal.php index fbba2d93e..ac6a6833a 100644 --- a/emhttp/plugins/dynamix/include/OpenTerminal.php +++ b/emhttp/plugins/dynamix/include/OpenTerminal.php @@ -44,10 +44,10 @@ switch ($_GET['tag']) { case 'ttyd': // check if ttyd already running $sock = "/var/run/ttyd.sock"; - exec("pgrep -f '$sock'", $ttyd_pid, $retval); + exec('pgrep --ns $$ -f '."'$sock'", $ttyd_pid, $retval); if ($retval == 0) { // check if there are any child processes, ie, curently open tty windows - exec("pgrep -P ".$ttyd_pid[0], $output, $retval); + exec('pgrep --ns $$ -P '.$ttyd_pid[0], $output, $retval); // no child processes, restart ttyd to pick up possible font size change if ($retval != 0) exec("kill ".$ttyd_pid[0]); } diff --git a/emhttp/plugins/dynamix/include/StartCommand.php b/emhttp/plugins/dynamix/include/StartCommand.php index 254c41501..b63d3bfdf 100644 --- a/emhttp/plugins/dynamix/include/StartCommand.php +++ b/emhttp/plugins/dynamix/include/StartCommand.php @@ -15,7 +15,7 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Secure.php"; function pgrep($proc) { - return exec("pgrep -f $proc"); + return exec('pgrep --ns $$ -f '."$proc"); } if (isset($_POST['kill']) && $_POST['kill'] > 1) { diff --git a/emhttp/plugins/dynamix/scripts/reiserfs_check b/emhttp/plugins/dynamix/scripts/reiserfs_check index 9896880ed..0ec66fa9b 100755 --- a/emhttp/plugins/dynamix/scripts/reiserfs_check +++ b/emhttp/plugins/dynamix/scripts/reiserfs_check @@ -16,7 +16,7 @@ case "$1" in else echo "Not available" fi; - pgrep -f "/sbin/reiserfsck $2" >/dev/null + pgrep --ns $$ -f "/sbin/reiserfsck $2" >/dev/null ;; 'cancel') pkill -f "/sbin/reiserfsck $2" diff --git a/etc/rc.d/rc.K b/etc/rc.d/rc.K index c8d075d8b..75e450339 100755 --- a/etc/rc.d/rc.K +++ b/etc/rc.d/rc.K @@ -99,7 +99,7 @@ if [[ -x /etc/rc.d/rc.acpid && -r /var/run/acpid.pid ]]; then # quit fi # Kill all processes. -OMITPIDS="$(for P in $(pgrep mdmon); do echo -o $P; done)" # Don't kill mdmon +OMITPIDS="$(for P in $(pgrep --ns $$ mdmon); do echo -o $P; done)" # Don't kill mdmon log "Sending all processes the SIGHUP signal." run killall5 -1 $OMITPIDS log "Waiting for processes to hang up" diff --git a/etc/rc.d/rc.acpid b/etc/rc.d/rc.acpid index bbc6f334f..09d71a234 100755 --- a/etc/rc.d/rc.acpid +++ b/etc/rc.d/rc.acpid @@ -40,7 +40,7 @@ acpid_stop(){ REPLY="Already stopped" else run kill $(cat /var/run/acpid.pid 2>/dev/null) - run killall acpid + run killall --ns $$ acpid if ! acpid_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi log "$DAEMON... $REPLY." diff --git a/etc/rc.d/rc.bind b/etc/rc.d/rc.bind index 1b0b4d6fb..5e6e1ca12 100644 --- a/etc/rc.d/rc.bind +++ b/etc/rc.d/rc.bind @@ -96,7 +96,7 @@ bind_stop() { fi # Kill named processes if there are any running: if ps axco command | grep -q -e "^named$"; then - echo "Stopping all named processes in this namespace: /bin/killall -SIGTERM --ns \$\$ named" + echo "Stopping all named processes in this namespace: /bin/killall -SIGTERM --ns $$ named" /bin/killall -SIGTERM --ns $$ named 2> /dev/null fi } diff --git a/etc/rc.d/rc.dnsmasq b/etc/rc.d/rc.dnsmasq index 1274cd831..f36c7a742 100644 --- a/etc/rc.d/rc.dnsmasq +++ b/etc/rc.d/rc.dnsmasq @@ -15,7 +15,7 @@ PIDFILE="/var/run/dnsmasq.pid" dnsmasq_running(){ sleep 0.1 - pgrep -l -F $PIDFILE 2>/dev/null | grep -q dnsmasq + pgrep --ns $$ -l -F $PIDFILE 2>/dev/null | grep -q dnsmasq } dnsmasq_start(){ diff --git a/etc/rc.d/rc.elogind b/etc/rc.d/rc.elogind index 146eb6d6d..503619f9b 100755 --- a/etc/rc.d/rc.elogind +++ b/etc/rc.d/rc.elogind @@ -29,7 +29,7 @@ PIDFILE="/run/elogind.pid" elogind_running(){ sleep 0.1 - pgrep -l -F $PIDFILE 2>/dev/null | grep -q elogind + pgrep --ns $$ -l -F $PIDFILE 2>/dev/null | grep -q elogind } elogind_start(){ diff --git a/etc/rc.d/rc.inetd b/etc/rc.d/rc.inetd index 765d58b0a..231c3f32e 100755 --- a/etc/rc.d/rc.inetd +++ b/etc/rc.d/rc.inetd @@ -35,7 +35,7 @@ inetd_stop() { if ! inetd_running; then REPLY="Already stopped" else - run killall inetd + run killall --ns $$ inetd if ! inetd_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi log "$DAEMON... $REPLY." diff --git a/etc/rc.d/rc.mcelog b/etc/rc.d/rc.mcelog index 4d3b173bb..a5a737038 100755 --- a/etc/rc.d/rc.mcelog +++ b/etc/rc.d/rc.mcelog @@ -74,7 +74,7 @@ mcelog_stop(){ if ! mcelog_running; then REPLY="Already stopped" else - killall -TERM $MCELOG + killall --ns $$ -TERM $MCELOG if ! mcelog_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi elif [[ $MCELOG_MODE == trigger && -f $TRIGGER ]]; then diff --git a/etc/rc.d/rc.messagebus b/etc/rc.d/rc.messagebus index 8a0187ed6..9fadc6b92 100755 --- a/etc/rc.d/rc.messagebus +++ b/etc/rc.d/rc.messagebus @@ -52,7 +52,7 @@ dbus_stop(){ else run kill $(cat $PIDFILE) # Just in case: - run killall dbus-daemon + run killall --ns $$ dbus-daemon rm -f $PIDFILE if ! dbus_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi @@ -65,7 +65,7 @@ dbus_reload(){ pid=$(cat $PIDFILE) run kill -HUP $pid else - run killall -HUP dbus-daemon + run killall --ns $$ -HUP dbus-daemon fi log "$DAEMON... Reloaded." } diff --git a/etc/rc.d/rc.nfsd b/etc/rc.d/rc.nfsd index e15f4ccba..8552df5f5 100755 --- a/etc/rc.d/rc.nfsd +++ b/etc/rc.d/rc.nfsd @@ -104,11 +104,11 @@ nfsd_stop(){ if ! nfsd_running; then REPLY="Already stopped" else - killall rpc.mountd 2>/dev/null - killall nfsd 2>/dev/null + killall --ns $$ rpc.mountd 2>/dev/null + killall --ns $$ nfsd 2>/dev/null sleep 1 - killall -9 nfsd 2>/dev/null - killall rpc.rquotad 2>/dev/null + killall --ns $$ -9 nfsd 2>/dev/null + killall --ns $$ rpc.rquotad 2>/dev/null run $EXPORTFS -au if ! nfsd_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi diff --git a/etc/rc.d/rc.ntpd b/etc/rc.d/rc.ntpd index b22fff338..cc9c05711 100755 --- a/etc/rc.d/rc.ntpd +++ b/etc/rc.d/rc.ntpd @@ -76,7 +76,7 @@ ntpd_stop(){ kill -HUP $(cat /var/run/ntpd.pid) rm -f /var/run/ntpd.pid else - killall -HUP -q ntpd + killall --ns $$ -HUP -q ntpd fi if ! ntpd_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi @@ -93,7 +93,7 @@ ntpd_restart(){ } ntpd_reload(){ - killall -HUP -q ntpd + killall --ns $$ -HUP -q ntpd . <(fromdos <$IDENT) ntpd_build $NTPD $OPTIONS 2>/dev/null diff --git a/etc/rc.d/rc.rpc b/etc/rc.d/rc.rpc index 825e9aa85..aa67bf35f 100755 --- a/etc/rc.d/rc.rpc +++ b/etc/rc.d/rc.rpc @@ -80,13 +80,13 @@ rpc_stop(){ if ! rpc_running; then REPLY="Already stopped" else - killall rpc.statd 2>/dev/null + killall --ns $$ rpc.statd 2>/dev/null sleep 1 - killall rpcbind 2>/dev/null + killall --ns $$ rpcbind 2>/dev/null sleep 1 - killall -9 rpc.statd 2>/dev/null # make sure :) + killall --ns $$ -9 rpc.statd 2>/dev/null # make sure :) sleep 1 - killall -9 rpcbind 2>/dev/null # make sure :) + killall --ns $$ -9 rpcbind 2>/dev/null # make sure :) if ! rpc_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi log "$DAEMON... $REPLY." diff --git a/etc/rc.d/rc.samba b/etc/rc.d/rc.samba index 089c4cda1..3b33f92a8 100755 --- a/etc/rc.d/rc.samba +++ b/etc/rc.d/rc.samba @@ -34,7 +34,7 @@ PRIVATE="/var/lib/samba/private" samba_running(){ sleep 0.1 - [[ $(pgrep -cf $SMBD) -gt 0 ]] + [[ $(pgrep --ns $$ -cf $SMBD) -gt 0 ]] } samba_waitfor_shutdown(){ diff --git a/etc/rc.d/rc.smartd b/etc/rc.d/rc.smartd index 8254b3942..24f5accd5 100644 --- a/etc/rc.d/rc.smartd +++ b/etc/rc.d/rc.smartd @@ -25,7 +25,7 @@ smart_stop() { if [ -r /run/smartd.pid ]; then kill $(cat /run/smartd.pid) else - killall smartd + killall --ns $$ smartd fi } diff --git a/etc/rc.d/rc.udev b/etc/rc.d/rc.udev index b89756fd2..6ccb97bfa 100755 --- a/etc/rc.d/rc.udev +++ b/etc/rc.d/rc.udev @@ -191,7 +191,7 @@ case "$1" in 'force-stop') log "Stopping udevd" udevadm control --exit - killall udevd 2>/dev/null + killall --ns $$ udevd 2>/dev/null ;; 'force-restart') log "Restarting udevd" diff --git a/etc/rc.d/rc.wsdd2 b/etc/rc.d/rc.wsdd2 index eedaf81c0..762566183 100755 --- a/etc/rc.d/rc.wsdd2 +++ b/etc/rc.d/rc.wsdd2 @@ -58,7 +58,7 @@ wsdd2_stop(){ if ! wsdd2_running; then REPLY="Already stopped" else - killall wsdd2 + killall --ns $$ wsdd2 if ! wsdd2_running; then REPLY="Stopped"; else REPLY="Failed"; fi fi log "$DAEMON... $REPLY." diff --git a/sbin/mover b/sbin/mover index 35547c092..336aebf89 100755 --- a/sbin/mover +++ b/sbin/mover @@ -117,7 +117,7 @@ empty() { killtree() { local pid=$1 child - for child in $(pgrep -P $pid); do + for child in $(pgrep --ns $$ -P $pid); do killtree $child done [ $pid -ne $$ ] && kill -TERM $pid