From b61e89600ea0053d8ab4a9d0e18809cc29828b92 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 16 May 2012 14:03:24 -0400 Subject: Teach mwexec and mwexec_bg how to optionally clear signal masks, and use that when launching ntp or ntpdate. --- etc/inc/util.inc | 19 +++++++++++++++++-- etc/rc.bootup | 2 +- etc/rc.newwanip | 2 +- etc/rc.newwanipv6 | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/etc/inc/util.inc b/etc/inc/util.inc index a052fbc..d53b885 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -953,7 +953,7 @@ function exec_command($command) { } /* wrapper for exec() */ -function mwexec($command, $mute = false) { +function mwexec($command, $mute = false, $clearsigmask = false) { global $g; if ($g['debug']) { @@ -962,7 +962,15 @@ function mwexec($command, $mute = false) { } $oarr = array(); $retval = 0; + + if ($clearsigmask) { + $oldset = array(); + pcntl_sigprocmask(SIG_SETMASK, array(), $oldset); + } $garbage = exec("$command 2>&1", $oarr, $retval); + if ($clearsigmask) { + pcntl_sigprocmask(SIG_SETMASK, $oldset); + } if(isset($config['system']['developerspew'])) $mute = false; @@ -974,7 +982,7 @@ function mwexec($command, $mute = false) { } /* wrapper for exec() in background */ -function mwexec_bg($command) { +function mwexec_bg($command, $clearsigmask = false) { global $g; if ($g['debug']) { @@ -982,7 +990,14 @@ function mwexec_bg($command) { echo "mwexec(): $command\n"; } + if ($clearsigmask) { + $oldset = array(); + pcntl_sigprocmask(SIG_SETMASK, array(), $oldset); + } exec("nohup $command > /dev/null 2>&1 &"); + if ($clearsigmask) { + pcntl_sigprocmask(SIG_SETMASK, $oldset); + } } /* unlink a file, if it exists */ diff --git a/etc/rc.bootup b/etc/rc.bootup index 721cea6..3b14cb1 100755 --- a/etc/rc.bootup +++ b/etc/rc.bootup @@ -309,7 +309,7 @@ system_routing_enable(); 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"); +mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true); /* start load balancer daemon */ relayd_configure(); diff --git a/etc/rc.newwanip b/etc/rc.newwanip index a33502c..999d0e8 100755 --- a/etc/rc.newwanip +++ b/etc/rc.newwanip @@ -51,7 +51,7 @@ function restart_packages() { /* restart packages */ system_ntp_configure(false); - mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh"); + mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true); log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages."); send_event("service reload packages"); } diff --git a/etc/rc.newwanipv6 b/etc/rc.newwanipv6 index 3571e40..7655106 100755 --- a/etc/rc.newwanipv6 +++ b/etc/rc.newwanipv6 @@ -63,7 +63,7 @@ function restart_packages() { /* restart packages */ system_ntp_configure(false); - mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh"); + mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true); log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages."); mwexec_bg("/etc/rc.start_packages"); } -- cgit v1.1