Commit 2dc29128 authored by Franco Fichtner's avatar Franco Fichtner

inc: mwexec_bg() ought to daemonize

Has it really been this way forever?  While there, chain
mwexec_bg() throgh mwexec() to avoid duplicated code and
increase error reporting.
parent 3ace0410
......@@ -656,10 +656,10 @@ function reload_all_sync() {
mwexec("/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd");
/* restart sshd */
mwexec('/usr/local/etc/rc.sshd');
mwexec_bg('/usr/local/etc/rc.sshd');
/* restart webConfigurator if needed */
mwexec('/usr/local/etc/rc.restart_webgui');
mwexec_bg('/usr/local/etc/rc.restart_webgui');
}
function setup_serial_port($when = 'save', $path = '')
......
......@@ -1000,32 +1000,29 @@ function mwexec($command, $mute = false, $clearsigmask = false)
$oldset = array();
pcntl_sigprocmask(SIG_SETMASK, array(), $oldset);
}
$garbage = exec("$command 2>&1", $oarr, $retval);
$garbage = exec("{$command} 2>&1", $oarr, $retval);
unset($garbage);
if ($clearsigmask) {
pcntl_sigprocmask(SIG_SETMASK, $oldset);
}
if(($retval <> 0) && ($mute === false)) {
$output = implode(" ", $oarr);
log_error(sprintf(gettext("The command '%1\$s' returned exit code '%2\$d', the output was '%3\$s' "), $command, $retval, $output));
if ($retval != 0 && $mute == false) {
$output = implode(' ', $oarr);
log_error(sprintf(gettext("The command '%s' returned exit code '%d', the output was '%s'"), $command, $retval, $output));
unset($output);
}
unset($oarr);
return $retval;
}
/* wrapper for exec() in background */
function mwexec_bg($command, $clearsigmask = false)
function mwexec_bg($command, $mute = false, $clearsigmask = false)
{
if ($clearsigmask) {
$oldset = array();
pcntl_sigprocmask(SIG_SETMASK, array(), $oldset);
}
$_gb = exec("/usr/bin/nohup $command > /dev/null 2>&1 &");
if ($clearsigmask) {
pcntl_sigprocmask(SIG_SETMASK, $oldset);
}
unset($_gb);
mwexec("/usr/sbin/daemon -f {$command}", $mute, $clearsigmask);
}
/* unlink a file, if it exists */
......
......@@ -264,7 +264,7 @@ services_unbound_configure();
echo "Starting NTP time client...";
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
system_ntp_configure(false);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", false, true);
echo "done.\n";
/* start load balancer daemon */
......
......@@ -50,7 +50,7 @@ function restart_packages() {
/* restart packages */
system_ntp_configure(false);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", false, true);
log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages.");
send_event("service reload packages");
}
......
......@@ -46,7 +46,7 @@ function restart_packages() {
/* restart packages */
system_ntp_configure(false);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", false, true);
log_error("{$g['product_name']} package system has detected an ip change $oldipv6 -> $curwanipv6 ... Restarting packages.");
send_event("service reload packages");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment