When downing an interface that uses DHCP, ifdown kills the daemons and waits for 100ms hoping that the DHCP client would die by that time. But running the DHCP deconfiguration hooks can take a long time and a later ifup may fail because of this reason.
In particular, ifdown && change /etc/network/interfaces to use a static address && ifup can fail by keeping the interface down. Now that start-stop-daemon can support -R, use it to wait for the DHCP client to actually terminate. This means that ifdown now depends on an implementation of start-stop-daemon. Signed-off-by: Nicolas Cavallari <[email protected]> --- networking/ifupdown.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 9c3640be7..5b344b96c 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -38,6 +38,10 @@ //config: help //config: Deactivate the specified interfaces. //config: +//config: If using DHCP, you must install either the full-blown +//config: start-stop-daemon or enable the "start-stop-daemon" applet in +//config: busybox. +//config: //config:config IFUPDOWN_IFSTATE_PATH //config: string "Absolute path to ifstate file" //config: default "/var/run/ifstate" @@ -628,7 +632,8 @@ static const struct dhcp_client_t ext_dhcp_clients[] ALIGN_PTR = { }, { "dhclient", "dhclient -pf /var/run/dhclient.%iface%.pid %iface%", - "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", + "start-stop-daemon -K -R 5 -n dhclient" + " -p /var/run/dhclient.%iface%.pid", }, { "pump", "pump -i %iface%[[ -h %hostname%]][[ -l %leasehours%]]", @@ -637,7 +642,7 @@ static const struct dhcp_client_t ext_dhcp_clients[] ALIGN_PTR = { { "udhcpc", "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -x hostname:%hostname%]][[ -c %client%]]" "[[ -s %script%]][[ %udhcpc_opts%]]", - "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", + "start-stop-daemon -K -R 5 -n udhcpc -p /var/run/udhcpc.%iface%.pid", }, }; # endif /* FEATURE_IFUPDOWN_EXTERNAL_DHCPC */ @@ -704,7 +709,7 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec) bb_simple_error_msg("warning: no dhcp clients found and stopped"); /* 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 */ + and it may come back up because the dhcp client is still shutting down */ usleep(100000); result += static_down(ifd, exec); return ((result == 3) ? 3 : 0); @@ -714,15 +719,11 @@ 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", + "start-stop-daemon -K -R 5 -n udhcpc -p /var/run/udhcpc.%iface%.pid", ifd, exec); /* 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); } -- 2.51.0 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
