busybox: mount: don't pass option "auto" to kernel
[opendreambox.git] / meta-opendreambox / recipes-core / busybox / busybox-1.19.4 / 0008-ifupdown-dhcp_down-wait-until-udhcpc-has-been-killed.patch
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/11] ifupdown: dhcp_down: wait until udhcpc has been killed
5
6 * Otherwise there's a race condition between ifdown and udhcpc,
7   which executes deconfig scripts in /etc/udhcpc.d.
8
9 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
10 ---
11  networking/ifupdown.c |   23 +++++++++++++++++------
12  1 file changed, 17 insertions(+), 6 deletions(-)
13
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)
20  {
21         int result;
22 -       result = execute(
23 -               "test -f /var/run/udhcpc.%iface%.pid && "
24 -               "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
25 -               ifd, exec);
26 +       char *pidfile_name;
27 +       pid_t pid_from_pidfile;
28 +
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 */
37 -       usleep(100000);
38 +       if (result && kill(pid_from_pidfile, SIGTERM) == 0) {
39 +               unsigned int i;
40 +               for (i = 0; i < 100; i++) {
41 +                       if (kill(pid_from_pidfile, 0) < 0) {
42 +                               result++;
43 +                               break;
44 +                       }
45 +                       usleep(100000);
46 +               }
47 +       }
48         result += static_down(ifd, exec);
49 -       return ((result == 3) ? 3 : 0);
50 +       return ((result == 4) ? 4 : 0);
51  }
52  # else
53  static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM,
54 -- 
55 1.7.10.4
56