diff options
-rw-r--r-- | etc/inc/interfaces.inc | 20 | ||||
-rw-r--r-- | usr/local/www/interfaces.php | 4 |
2 files changed, 17 insertions, 7 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 045ca17..a4390ad 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -1242,10 +1242,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = } break; case "dhcp": - $pid = find_dhclient_process($realif); - if($pid) - posix_kill($pid, SIGTERM); - sleep(1); + kill_dhclient_process($realif); unlink_if_exists("{$g['varetc_path']}/dhclient_{$interface}.conf"); if(does_interface_exist("$realif")) { mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); @@ -2801,6 +2798,21 @@ function find_dhclient_process($interface) { return intval($pid); } +function kill_dhclient_process($interface) { + if (empty($interface) || !does_interface_exist($interface)) + return; + + $i = 0; + while ((($pid = find_dhclient_process($interface)) != 0) && ($i < 3)) { + /* 3rd time make it die for sure */ + $sig = ($i == 2 ? SIGKILL : SIGTERM); + posix_kill($pid, $sig); + sleep(1); + $i++; + } + unset($i); +} + function find_dhcp6c_process($interface) { global $g; diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index e1d05c0..6aa0014 100644 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -797,9 +797,7 @@ if ($_POST['apply']) { $wancfg['if'] = $a_ppps[$pppid]['ports']; unset($a_ppps[$pppid]); } else if ($wancfg['ipaddr'] == "dhcp") { - $pid = find_dhclient_process($wancfg['if']); - if($pid) - posix_kill($pid, SIGTERM); + kill_dhclient_process($wancfg['if']); } if ($wancfg['ipaddrv6'] == "dhcp6") { $pid = find_dhcp6c_process($wancfg['if']); |