File sysconfig-ifup-dhcp-running-detection.bnc562030.diff of Package sysconfig
From eccfdbf3b0ebe32024ee45d90aac4ea622e55507 Mon Sep 17 00:00:00 2001
From: mt <mt@bf393798-0adf-0310-9952-bd479070b6c1>
Date: Thu, 10 Dec 2009 16:04:34 +0000
Subject: [PATCH] Improved detection if a dhcp client is running, causing ifup-dhcp and
the network script to report false failures, when the client forks at
the moment of the check (bnc#562030 and others).
---
scripts/functions | 51 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/scripts/functions b/scripts/functions
index 10f9971..7eb6953 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -712,7 +712,7 @@ netcontrol_running() {
# returns 0 if ifup is currently working on this interface
ifup_on_iface() {
- ps axww | grep -qs "[i]fup.* $INTERFACE\>"
+ ps axhww | grep -qs "[i]fup.* $INTERFACE\>"
}
# returns 0 if there is a dhcp client running on this interface
@@ -721,45 +721,66 @@ ifup_on_iface() {
# Usually it should not happen that more then one dhcpcd is running on one
# interface, but it may happen. So better safe than sorry!
dhcpc4_on_iface() {
- local pid line retval=1
+ local pid line
+ typeset -i retval=1
if [ "x$DHCLIENT" != x -a \
"x$INTERFACE" != x ] ; then
+ # when the dhcp client forks, it may be not visible
+ # in the process list for a short (usleep) while...
+ typeset -i retries=3
+ for ((; retries > 0; retries--)) ; do
while read pid line; do
retval=0
test "x$1" == "x-q" && break
echo $pid
- done < <(ps axww | grep -Es "[ /]$DHCLIENT\>.*\<$INTERFACE\>$")
+ done < <(ps axhww | grep -Es "[ /]$DHCLIENT\>.*\<$INTERFACE\>$")
+ (( retval == 0 )) && break || usleep 100000
+ done
fi
return $retval
}
dhcpc6_on_iface() {
- local pid line retval=1
+ local pid line
+ typeset -i retval=1
if [ "x$DHCLIENT6" != x -a \
"x$INTERFACE" != x ] ; then
+ # when the dhcp client forks, it may be not visible
+ # in the process list for a short (usleep) while...
+ typeset -i retries=3
+ for ((; retries > 0; retries--)) ; do
while read pid line; do
retval=0
test "x$1" == "x-q" && break
echo $pid
- done < <(ps axww | grep -Es "[ /]$DHCLIENT6\>.*\<$INTERFACE\>$")
+ done < <(ps axhww | grep -Es "[ /]$DHCLIENT6\>.*\<$INTERFACE\>$")
+ (( retval == 0 )) && break || usleep 100000
+ done
fi
return $retval
}
dhcpc_on_iface() {
- local pid line retval=1
+ local pid line
+ typeset -i retval=1
if [ "x$DHCLIENT" != x -a \
"x$DHCLIENT6" != x -a \
"x$INTERFACE" != x ] ; then
+ # when the dhcp client forks, it may be not visible
+ # in the process list for a short (usleep) while...
+ typeset -i retries=3
+ for ((; retries > 0; retries--)) ; do
while read pid line; do
retval=0
test "$1" == "-q" && break
echo $pid
- done < <(ps axww | grep -Es "[ /]($DHCLIENT|$DHCLIENT6)\>.*\<$INTERFACE\>$")
+ done < <(ps axhww | grep -Es "[ /]($DHCLIENT|$DHCLIENT6)\>.*\<$INTERFACE\>$")
+ (( retval == 0 )) && break || usleep 100000
+ done
fi
return $retval
}
any_dhcpc_on_iface()
{
- local retval=1
+ typeset -i retval=1
if [ "x$INTERFACE" != x ] ; then
eval local `grep -h '^DHCLIENT_BIN=' \
/etc/sysconfig/network/dhcp`
@@ -780,14 +801,20 @@ any_dhcpc_on_iface()
dhclients=(${dhclients[@]} "$x")
done
if [ ${#dhclients[@]} -gt 0 ] ; then
- local pid line
- dhclients=${dhclients[@]}
- dhclients=${dhclients// /|}
+ local pid line
+ dhclients=${dhclients[@]}
+ dhclients=${dhclients// /|}
+ # when the dhcp client forks, it may be not visible
+ # in the process list for a short (usleep) while...
+ typeset -i retries=3
+ for ((; retries > 0; retries--)) ; do
while read pid line; do
retval=0
test "$1" == "-q" && break
echo $pid
- done < <(ps axww | grep -Es "[ /]($dhclients)\>.*\<$INTERFACE\>$")
+ done < <(ps axhww | grep -Es "[ /]($dhclients)\>.*\<$INTERFACE\>$")
+ (( retval == 0 )) && break || usleep 100000
+ done
fi
fi
return $retval
--
1.6.4.2