1 From 517f8da0345752d3cc5e2c99b8acd88c60355373 Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Mon, 14 May 2012 16:20:36 +0200
4 Subject: [PATCH 08/10] ifupdown: dhcp_down: wait until udhcpc has been killed
6 * Otherwise there's a race condition between ifdown and udhcpc,
7 which executes deconfig scripts in /etc/udhcpc.d.
9 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
11 networking/ifupdown.c | 23 +++++++++++++++++------
12 1 file changed, 17 insertions(+), 6 deletions(-)
14 diff --git a/networking/ifupdown.c b/networking/ifupdown.c
15 index 5c3dcec..35e5035 100644
16 --- a/networking/ifupdown.c
17 +++ b/networking/ifupdown.c
18 @@ -618,18 +618,29 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
19 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
23 - "test -f /var/run/udhcpc.%iface%.pid && "
24 - "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
27 + pid_t pid_from_pidfile;
29 + pidfile_name = xasprintf(_PATH_VARRUN "udhcpc.%s.pid", ifd->iface);
30 + pid_from_pidfile = read_pidfile(pidfile_name);
31 + result = (pid_from_pidfile > 0);
32 /* Also bring the hardware interface down since
33 killing the dhcp client alone doesn't do it.
34 This enables consecutive ifup->ifdown->ifup */
35 /* Sleep a bit, otherwise static_down tries to bring down interface too soon,
36 and it may come back up because udhcpc is still shutting down */
38 + if (result && kill(pid_from_pidfile, SIGTERM) == 0) {
40 + for (i = 0; i < 100; i++) {
41 + if (kill(pid_from_pidfile, 0) < 0) {
48 result += static_down(ifd, exec);
49 - return ((result == 3) ? 3 : 0);
50 + return ((result == 4) ? 4 : 0);
53 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM,