From: Jeroen De Wachter <[email protected]>

when ifdown gets called on a configuration that uses DHCP, it
kills the udhcpc client by killing the process with the id in
the udhcpc pid file (/var/run/udhcpc.%iface%.pid)

However, when avahi-autoipd is in play, that pid file does not
exist (due to a modified /usr/share/udhcpc/default.script that
launches the avahi autoipd stuff) and killing the process
fails.

Due to the way iface_down is written:

static int iface_down(struct interface_defn_t *iface)
{
    if (!iface->method->down(iface,check)) return -1;
    set_environ(iface, "stop");
    if (!execute_all(iface, "down")) return 0;
    if (!iface->method->down(iface, doit)) return 0; // <-- returns prematurely
    if (!execute_all(iface, "post-down")) return 0;
    return 1;
}

the post-down scripts are no longer executed, even though
nothing has actually gone wrong...
---
 networking/ifupdown.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index bf88b1c..caa422a 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -572,15 +572,34 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t 
*ifd, execfn *exec)
 #elif ENABLE_UDHCPC
 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
-       int result;
-       result = execute("kill "
-                      "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, 
exec);
+       int result = 1;
+       struct stat buf;
+       char* file;
+
+       /*
+         Check if the udhcpc pid file exists before trying to use it
+        */
+       file = parse("/var/run/udhcpc.%iface%.pid", ifd);
+       if (!file)
+       {
+               /* parse error? */
+               return 0;
+       }
+
+       if (!stat(file, &buf))
+       {
+               result = execute("kill "
+                                                "`cat 
/var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
+               /* 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);
+       }
+
+       free(file);
+
        /* 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);
        result += static_down(ifd, exec);
        return ((result == 3) ? 3 : 0);
 }
-- 
1.6.3.3

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to