From 46894ef91eb34754bce54ec59fecd4409225b550 Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 9 Jul 2016 03:34:48 +0100 Subject: [PATCH] Fix checking dnsmasq starting/stopping --- includes/dhcp.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 48b122b3..6dfa93c9 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -36,11 +36,18 @@ function DisplayDHCPConfig() { $status->addMessage('dnsmasq already running', 'info'); } else { $line = system('sudo /etc/init.d/dnsmasq start',$return); - exec( 'pidof dnsmasq | wc -l',$dnsmasq ); - if ($dnsmasq[0] == 0) { + $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 { $status->addMessage('Successfully started dnsmasq', 'success'); + $dnsmasq_state = true; } } } else { @@ -50,9 +57,16 @@ function DisplayDHCPConfig() { if (CSRFValidate()) { if ($dnsmasq_state) { $line = system('sudo /etc/init.d/dnsmasq stop',$return); - exec( 'pidof dnsmasq | wc -l',$dnsmasq ); - if ($dnsmasq[0] == 0) { + $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('Successfully stopped dnsmasq', 'success'); + $dnsmasq_state = false; } else { $status->addMessage('Failed to stop dnsmasq', 'danger'); }