[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 2/5] ifupdown: dhcp_down: wait until udhcpc has been killed
From:       Andreas Oberritter <obi () opendreambox ! org>
Date:       2013-03-20 14:31:24
Message-ID: 1363789887-30252-2-git-send-email-obi () opendreambox ! org
[Download RAW message or body]

* Otherwise there's a race condition between ifdown and udhcpc,
  which executes deconfig scripts in /etc/udhcpc.d.

Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
---
 networking/ifupdown.c |   23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 0f0857c..61c6607 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -612,18 +612,29 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
 	int result;
-	result = execute(
-		"test -f /var/run/udhcpc.%iface%.pid && "
-		"kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
-		ifd, exec);
+	char *pidfile_name;
+	pid_t pid_from_pidfile;
+
+	pidfile_name = xasprintf(_PATH_VARRUN "udhcpc.%s.pid", ifd->iface);
+	pid_from_pidfile = read_pidfile(pidfile_name);
+	result = (pid_from_pidfile > 0);
 	/* Also bring the hardware interface down since
 	   killing the dhcp client alone doesn't do it.
 	   This enables consecutive ifup->ifdown->ifup */
 	/* Sleep a bit, otherwise static_down tries to bring down interface too soon,
 	   and it may come back up because udhcpc is still shutting down */
-	usleep(100000);
+	if (result && kill(pid_from_pidfile, SIGTERM) == 0) {
+		unsigned int i;
+		for (i = 0; i < 100; i++) {
+			if (kill(pid_from_pidfile, 0) < 0) {
+				result++;
+				break;
+			}
+			usleep(100000);
+		}
+	}
 	result += static_down(ifd, exec);
-	return ((result == 3) ? 3 : 0);
+	return ((result == 4) ? 4 : 0);
 }
 # else
 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM,
-- 
1.7.10.4

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic