From bfae272b0f20708d52b54a00a716668399d088ce Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 9 Jul 2016 03:46:21 +0100 Subject: [PATCH] Better checking --- includes/dhcp.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 6dfa93c9..d173547a 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -35,19 +35,12 @@ function DisplayDHCPConfig() { if ($dnsmasq_state) { $status->addMessage('dnsmasq already running', 'info'); } else { - $line = system('sudo /etc/init.d/dnsmasq start',$return); - $n_tries = 0; - while ($n_tries < 5) { - exec( 'pidof dnsmasq | wc -l',$dnsmasq ); - if (end($dnsmasq) > 0) break; - sleep(1); - $n_tries += 1; - } - if (end($dnsmasq) == 0) { - $status->addMessage('Failed to start dnsmasq', 'danger'); - } else { + exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); + if ($return == 0) { $status->addMessage('Successfully started dnsmasq', 'success'); $dnsmasq_state = true; + } else { + $status->addMessage('Failed to start dnsmasq', 'danger'); } } } else { @@ -56,15 +49,8 @@ function DisplayDHCPConfig() { } elseif( isset($_POST['stopdhcpd'] ) ) { if (CSRFValidate()) { if ($dnsmasq_state) { - $line = system('sudo /etc/init.d/dnsmasq stop',$return); - $n_tries = 0; - while ($n_tries < 5) { - exec( 'pidof dnsmasq | wc -l',$dnsmasq ); - if (end($dnsmasq) == 0) break; - sleep(1); - $n_tries += 1; - } - if (end($dnsmasq) == 0) { + exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); + if ($return == 0) { $status->addMessage('Successfully stopped dnsmasq', 'success'); $dnsmasq_state = false; } else {