Skip to content

Commit

Permalink
interfaces: better wait for dhclient exit
Browse files Browse the repository at this point in the history
PR: https://forum.opnsense.org/index.php?topic=4682.0

(cherry picked from commit 844d6b5)
(cherry picked from commit b8c9eb4)
(cherry picked from commit 2d03d19)
  • Loading branch information
fichtner committed Mar 4, 2017
1 parent f43c605 commit bee13d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
10 changes: 1 addition & 9 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2453,15 +2453,7 @@ function kill_dhclient_process($interface)
return;
}

$i = 0;
while ((($pid = find_dhclient_process($interface)) != 0) && ($i < 3)) {
/* 3rd time make it die for sure */
$sig = ($i == 2 ? 'KILL' : 'TERM');
exec(sprintf('/bin/kill -%s %s', $sig, $pid));
sleep(1);
$i++;
}
unset($i);
killbypid(find_dhclient_process($interface), 'TERM', true);
}

function interface_vlan_mtu_configured($realhwif, $mtu)
Expand Down
18 changes: 11 additions & 7 deletions src/etc/inc/util.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2015-2017 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2004-2007 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Expand Down Expand Up @@ -41,12 +41,14 @@ function killbyname($procname, $sig = 'TERM')

function killbypid($pidfile, $sig = 'TERM', $waitforit = false)
{
if (!isvalidpid($pidfile)) {
if (is_numeric($pidfile) && $pidfile > 1) {
mwexecf('/bin/kill -%s %s', array($sig, $pidfile));
} elseif (isvalidpid($pidfile)) {
mwexecf('/bin/pkill -%s -F %s', array($sig, $pidfile));
} else {
return;
}

mwexecf('/bin/pkill -%s -F %s', array($sig, $pidfile));

if (!$waitforit) {
return;
}
Expand All @@ -58,11 +60,13 @@ function killbypid($pidfile, $sig = 'TERM', $waitforit = false)

function isvalidpid($pidfile)
{
if (!file_exists($pidfile)) {
return false;
if (is_numeric($pidfile) && $pidfile > 1) {
return mwexecf('/bin/kill -0 %s', $pidfile, true) == 0;
} elseif (file_exists($pidfile)) {
return mwexecf('/bin/pgrep -nF %s', $pidfile, true) == 0;
}

return mwexecf('/bin/pgrep -nF %s', $pidfile, true) == 0;
return false;
}

function is_process_running($process)
Expand Down

0 comments on commit bee13d3

Please sign in to comment.