udhcpc: don't exit after backgrounding on -n -b
authorAndrey Mazo <ahippo@yandex.com>
Fri, 22 Feb 2019 21:46:19 +0000 (16:46 -0500)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 27 Feb 2019 07:27:47 +0000 (08:27 +0100)
Currently, running "udhcpc -n -b" causes udhcpc to go to background and
then exit after some time unless a lease is obtained.

It's not very useful to do so
as the calling process doesn't know
if the lease was obtained or not anyway.

The code actually tries to favor "-b" over "-n",
but doesn't clear "-n" flag while clearing "-b" after backgrounding.

So, clear "-n" flag after going into background.
This effectively makes "-b" override "-n" completely
and "-n -b" behave the same as "-b".

This allows to override default "-n" option, passed to udhcpc by ifupdown,
without recompiling busybox.

URL: https://bugs.busybox.net/11691

Signed-off-by: Andrey Mazo <ahippo@yandex.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/d6_dhcpc.c
networking/udhcp/dhcpc.c

index 38c91cbb404250ad3c96912a0cf97dbf970956ec..8a4a4b7a5b750271f2c8e79fc48f72b3ced38dad 100644 (file)
@@ -1370,7 +1370,13 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
                                        bb_error_msg("no lease, forking to background");
                                        client_background();
                                        /* do not background again! */
-                                       opt = ((opt & ~OPT_b) | OPT_f);
+                                       opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f);
+                                       /* ^^^ also disables -n (-b takes priority over -n):
+                                        * ifup's default udhcpc options are -R -n,
+                                        * and users want to be able to add -b
+                                        * (in a config file) to make it background
+                                        * _and not exit_.
+                                        */
                                } else
 #endif
                                if (opt & OPT_n) { /* abort if no lease */
index d491e8906c14a7c194f71015e985d101db3b13e7..e2fb18aba93ddd6c7f6f81f3232a0949681c0ba4 100644 (file)
@@ -1484,7 +1484,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                                        bb_error_msg("no lease, forking to background");
                                        client_background();
                                        /* do not background again! */
-                                       opt = ((opt & ~OPT_b) | OPT_f);
+                                       opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f);
+                                       /* ^^^ also disables -n (-b takes priority over -n):
+                                        * ifup's default udhcpc options are -R -n,
+                                        * and users want to be able to add -b
+                                        * (in a config file) to make it background
+                                        * _and not exit_.
+                                        */
                                } else
 #endif
                                if (opt & OPT_n) { /* abort if no lease */