[BusyBox] [PATCH] add udhcpcd --foreground option

vda vda at port.imtp.ilyichevsk.odessa.ua
Tue Feb 17 08:12:27 UTC 2004


I want this because I run my daemons under daemontools.
Although I can run auto-daemonizing programs under
daemontools too, it is not a pretty sight.

Luckily, most daemons have a 'do not background myself'
flag or config option, and I use that. Busybox udhcpcd
had no such option. This patch adds it.

Patch against pre6. Tested.
--
vda

--- busybox-1.00-pre6/networking/udhcp/dhcpd.c.orig     Sat Jan 31 01:45:12 2004
+++ busybox-1.00-pre6/networking/udhcp/dhcpd.c  Mon Feb  2 11:50:25 2004
@@ -35,6 +35,7 @@
 #include <sys/ioctl.h>
 #include <time.h>
 #include <sys/time.h>
+#include <getopt.h>
 
 #include "dhcpd.h"
 #include "arpping.h"
@@ -70,7 +71,33 @@
        struct dhcpOfferedAddr *lease;
        int max_sock;
        unsigned long num_ips;
-
+       int daemonize = 1;
+
+       static const struct option arg_options[] = {
+               {"foreground",  no_argument, 0, 'f'},
+               {0, 0, 0, 0}
+       };
+
+       /* get options */
+       while (1) {
+               int option_index = 0;
+               int c = getopt_long(argc, argv, "f", arg_options, &option_index);
+               if (c == -1) {
+                       argv += optind-1;
+                       argc -= optind-1;
+                       break;
+               }
+
+               switch (c) {
+               case 'f':
+                       daemonize = 0;
+                       break;
+               default:
+                       /* add an error msg here */
+                       return 1;
+               }
+       }
+
        memset(&server_config, 0, sizeof(struct server_config_t));
        read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);

@@ -100,7 +127,8 @@
                return 1;
 
 #ifndef UDHCP_DEBUG
-       background(server_config.pidfile); /* hold lock during fork. */
+       if(daemonize)
+               background(server_config.pidfile); /* hold lock during fork. */
 #endif

        /* Setup the signal pipe */




More information about the busybox mailing list