Currently zcip can either daemonize immediately or stay in the
foreground indefinitely (with -f). However it is sometimes useful to
have it stay in foreground while obtaining an address, then
daemonize. This allows to have a boot process that blocks until an
address has been established, then goes on and starts up services that
need to know the interface address when they start.

avahi-autoipd has option -w to do this, udhcpc does it as well. Add
this feature to zcip.

function                                             old     new   delta
zcip_main                                           1395    1418     +23
.rodata                                              776     793     +17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0)               Total: 40 bytes

Signed-off-by: Luca Ceresoli <[email protected]>
---
 networking/zcip.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/networking/zcip.c b/networking/zcip.c
index 1d69105550a3..15540e7c4462 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -28,6 +28,7 @@
 //usage:#define zcip_full_usage "\n\n"
 //usage:       "Manage a ZeroConf IPv4 link-local address\n"
 //usage:     "\n       -f              Run in foreground"
+//usage:     "\n       -w              Daemonize after obtaining address"
 //usage:     "\n       -q              Quit after obtaining address"
 //usage:     "\n       -r 169.254.x.x  Request this address first"
 //usage:     "\n       -l x.x.0.0      Use this range instead of 169.254"
@@ -229,10 +230,11 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
 
 #define FOREGROUND (opts & 1)
 #define QUIT       (opts & 2)
+#define DAEMONWAIT (opts & 8)
        // Parse commandline: prog [options] ifname script
        // exactly 2 args; -v accumulates and implies -f
-       opt_complementary = "=2:vv:vf";
-       opts = getopt32(argv, "fqr:l:v", &r_opt, &l_opt, &verbose);
+       opt_complementary = "=2:vv:vf:w--fq:f--w:q--w";
+       opts = getopt32(argv, "fqr:wl:v", &r_opt, &l_opt, &verbose);
 #if !BB_MMU
        // on NOMMU reexec early (or else we will rerun things twice)
        if (!FOREGROUND)
@@ -315,7 +317,8 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
        // Daemonize now; don't delay system startup
        if (!FOREGROUND) {
 #if BB_MMU
-               bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/);
+               if (!DAEMONWAIT)
+                       bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/);
 #endif
                bb_info_msg("start, interface %s", argv_intf);
        }
@@ -411,6 +414,10 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                                // NOTE: all other exit paths should deconfig...
                                if (QUIT)
                                        return EXIT_SUCCESS;
+#if BB_MMU
+                               if (!FOREGROUND && DAEMONWAIT)
+                                       bb_daemonize(0 /*was: 
DAEMON_CHDIR_ROOT*/);
+#endif
                                // fall through: switch to MONITOR
                        default:
                        // case DEFEND:
-- 
1.9.1

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

Reply via email to