killall and pgrep updates.

Set --ns $$ on commands.
This commit is contained in:
SimonFair
2024-10-10 19:18:54 +01:00
parent 3c007fa1d0
commit 80d567dfde
25 changed files with 38 additions and 38 deletions

View File

@@ -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();

View File

@@ -19,7 +19,7 @@ Code="e944"
?>
<?
// Remove stale /tmp/plugin/*.plg entries (check that script 'plugin' is not running to avoid clashes)
if (!exec("pgrep -f $docroot/plugins/dynamix.plugin.manager/scripts/plugin")) {
if (!exec('pgrep --ns $$ -f '."$docroot/plugins/dynamix.plugin.manager/scripts/plugin")) {
foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
}
$check = $notify['version'] ? 0 : 1;

View File

@@ -69,7 +69,7 @@ $cache_type = $cache_rate = [];
$parity = _var($var,'mdResync');
$mover = file_exists('/var/run/mover.pid');
$btrfs = exec('pgrep -cf /sbin/btrfs');
$btrfs = exec('pgrep --ns $$ -cf /sbin/btrfs');
$vdisk = exec("grep -Pom1 '^DOCKER_IMAGE_TYPE=\"\\K[^\"]+' /boot/config/docker.cfg 2>/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';}));

View File

@@ -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)'");

View File

@@ -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";

View File

@@ -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":

View File

@@ -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]);
}

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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"

View File

@@ -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."

View File

@@ -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
}

View File

@@ -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(){

View File

@@ -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(){

View File

@@ -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."

View File

@@ -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

View File

@@ -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."
}

View File

@@ -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

View File

@@ -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

View File

@@ -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."

View File

@@ -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(){

View File

@@ -25,7 +25,7 @@ smart_stop() {
if [ -r /run/smartd.pid ]; then
kill $(cat /run/smartd.pid)
else
killall smartd
killall --ns $$ smartd
fi
}

View File

@@ -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"

View File

@@ -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."

View File

@@ -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