]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove some ints and replace with our option mask.
authorRoy Marples <roy@marples.name>
Fri, 5 Sep 2008 07:22:03 +0000 (07:22 +0000)
committerRoy Marples <roy@marples.name>
Fri, 5 Sep 2008 07:22:03 +0000 (07:22 +0000)
bind.c
bind.h
dhcpcd.c
dhcpcd.h
if-options.c
if-options.h

diff --git a/bind.c b/bind.c
index 6e7367fc0fec8877d76c28e1c09520f82efba0da..b0f7c9ba9eb8946ca00a20b41f7a96d3d12b5498 100644 (file)
--- a/bind.c
+++ b/bind.c
@@ -42,9 +42,6 @@
 #include "net.h"
 #include "signals.h"
 
-static int daemonised = 0;
-int can_daemonise = 1;
-
 #ifndef THERE_IS_NO_FORK
 pid_t
 daemonise(void)
@@ -55,7 +52,7 @@ daemonise(void)
        char buf = '\0';
        int sidpipe[2];
 
-       if (daemonised || !can_daemonise)
+       if (options & DHCPCD_DAEMONISED || !(options & DHCPCD_DAEMONISE))
                return 0;
        sigfillset(&full);
        sigprocmask(SIG_SETMASK, &full, &old);
@@ -93,7 +90,7 @@ daemonise(void)
                pidfd = -1;
                exit(EXIT_SUCCESS);
        }
-       daemonised = 1;
+       options |= DHCPCD_DAEMONISED;
        sigprocmask(SIG_SETMASK, &old, NULL);
        return pid;
 }
diff --git a/bind.h b/bind.h
index f64d1c66d3f22ea2ce767870bbeba63901809f10..a8d6e3a818de6a4755fba5db99cec3dbbdb41e29 100644 (file)
--- a/bind.h
+++ b/bind.h
@@ -35,6 +35,5 @@
 pid_t daemonise(void);
 #endif
 
-extern int can_daemonise;
 void bind_interface(void *);
 #endif
index 658147e2b2251bbc1745fb662dd8ceebb11a7241..023157986476458e7f25f568eec08a62a69f100d 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -64,7 +64,7 @@ const char copyright[] = "Copyright (c) 2006-2008 Roy Marples";
 /* We should define a maximum for the NAK exponential backoff */ 
 #define NAKOFF_MAX              60
 
-int master = 0;
+int options = 0;
 int pidfd = -1;
 static char **ifv = NULL;
 static int ifc = 0;
@@ -143,7 +143,7 @@ cleanup(void)
        if (linkfd != -1)
                close(linkfd);
        if (pidfd > -1) {
-               if (master) {
+               if (options & DHCPCD_MASTER) {
                        if (stop_control() == -1)
                                logger(LOG_ERR, "stop_control: %s",
                                       strerror(errno));
@@ -211,7 +211,7 @@ stop_interface(struct interface *iface)
        else
                ifaces = iface->next;
        free_interface(ifp);
-       if (!master)
+       if (!(options & DHCPCD_MASTER))
                exit(EXIT_FAILURE);
 }
 
@@ -960,8 +960,7 @@ main(int argc, char **argv)
 {
        struct if_options *ifo;
        struct interface *iface;
-       int opt, oi = 0, test = 0, signal_fd, sig = 0, i, control_fd;
-       int background = 0;
+       int opt, oi = 0, signal_fd, sig = 0, i, control_fd;
        pid_t pid;
        struct timespec ts;
 
@@ -982,9 +981,14 @@ main(int argc, char **argv)
                }
        }
 
+       options = DHCPCD_DAEMONISE;
+
        while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
        {
                switch (opt) {
+               case 'b':
+                       options |= DHCPCD_BACKGROUND;
+                       break;
                case 'd':
                        setloglevel(LOG_DEBUG);
                        break;
@@ -1000,8 +1004,11 @@ main(int argc, char **argv)
                case 'x':
                        sig = SIGTERM;
                        break;
+               case 'B':
+                       options &= ~DHCPCD_DAEMONISE;
+                       break;
                case 'T':
-                       test = 1;
+                       options |= DHCPCD_TEST | DHCPCD_PERSISTENT;
                        break;
                case 'V':
                        print_options();
@@ -1026,11 +1033,9 @@ main(int argc, char **argv)
                snprintf(pidfile, sizeof(pidfile), PIDFILE, "-", argv[optind]);
        else {
                snprintf(pidfile, sizeof(pidfile), PIDFILE, "", "");
-               master = 1;
+               options |= DHCPCD_MASTER;
        }
        
-       if (test)
-               ifo->options |= DHCPCD_TEST | DHCPCD_PERSISTENT;
 #ifdef THERE_IS_NO_FORK
        ifo->options &= ~DHCPCD_DAEMONISE;
 #endif
@@ -1039,7 +1044,7 @@ main(int argc, char **argv)
        umask(022);
        atexit(cleanup);
 
-       if (!master) {
+       if (!(options & DHCPCD_MASTER)) {
                control_fd = open_control();
                if (control_fd != -1) {
                        logger(LOG_INFO, "sending commands to master dhcpcd process");
@@ -1084,7 +1089,7 @@ main(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
-       if (!(ifo->options & DHCPCD_TEST)) {
+       if (!(options & DHCPCD_TEST)) {
                if ((pid = read_pid()) > 0 &&
                    kill(pid, 0) == 0)
                {
@@ -1120,7 +1125,7 @@ main(int argc, char **argv)
                exit(EXIT_FAILURE);
        add_event(signal_fd, handle_signal, NULL);
 
-       if (master) {
+       if (options & DHCPCD_MASTER) {
                if (start_control() == -1) {
                        logger(LOG_ERR, "start_control: %s", strerror(errno));
                        exit(EXIT_FAILURE);
@@ -1136,17 +1141,11 @@ main(int argc, char **argv)
                        add_event(linkfd, handle_link, NULL);
        }
 
-       if (!(ifo->options & DHCPCD_DAEMONISE))
-               can_daemonise = 0;
-       if (can_daemonise) {
-               if (ifo->options & DHCPCD_BACKGROUND)
-                       background = 1;
-               else {
-                       oi = ifo->timeout;
-                       if (ifo->options & DHCPCD_IPV4LL)
-                               oi += 10;
-                       add_timeout_sec(oi, handle_exit_timeout, NULL);
-               }
+       if (options & DHCPCD_DAEMONISE && !(options & DHCPCD_BACKGROUND)) {
+               oi = ifo->timeout;
+               if (ifo->options & DHCPCD_IPV4LL)
+                       oi += 10;
+               add_timeout_sec(oi, handle_exit_timeout, NULL);
        }
        free_options(ifo);
 
@@ -1159,7 +1158,7 @@ main(int argc, char **argv)
                logger(LOG_ERR, "interface `%s' does not exist", ifv[0]);
                exit(EXIT_FAILURE);
        }
-       if (background)
+       if (options & DHCPCD_BACKGROUND)
                daemonise();
        start_eloop();
        /* NOTREACHED */
index 608a41d09f5e6f382275a3d36394cc163c371809..0860507498f547ed27427eaf6379bcd0c309802e 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -105,6 +105,7 @@ struct interface
 };
 
 extern int pidfd;
+extern int options;
 
 int handle_args(int, char **);
 void handle_exit_timeout(void *);
index f6f9140bdc36866049544fc4c05c986eb8bf6792..7d037a4edf4e80942f2b0ddf783785f8a9636244 100644 (file)
@@ -257,14 +257,16 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
        struct in_addr addr;
 
        switch(opt) {
-       case 'b':
-               ifo->options |= DHCPCD_BACKGROUND;
+       case 'b': /* FALLTHROUGH */
+       case 'd': /* FALLTHROUGH */
+       case 'k': /* FALLTHROUGH */
+       case 'n': /* FALLTHROUGH */
+       case 'x': /* FALLTHROUGH */
+       case 'B': /* We need to handle non interface options */
                break;
        case 'c':
                strlcpy(ifo->script, arg, sizeof(ifo->script));
                break;
-       case 'd':
-               break;
        case 'h':
                if (arg)
                        s = parse_string(ifo->hostname + 1,
@@ -293,8 +295,6 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                }
                *ifo->vendorclassid = (uint8_t)s;
                break;
-       case 'k':
-               break;
        case 'l':
                if (*arg == '-') {
                        logger(LOG_ERR,
@@ -315,8 +315,6 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                        return -1;
                }
                break;
-       case 'n':
-               break;
        case 'o':
                if (make_option_mask(ifo->requestmask, arg, 1) != 0) {
                        logger(LOG_ERR, "unknown option `%s'", arg);
@@ -417,16 +415,11 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                        ifo->vendor[0] += s + 2;
                }
                break;
-       case 'x':
-               break;
        case 'A':
                ifo->options &= ~DHCPCD_ARP;
                /* IPv4LL requires ARP */
                ifo->options &= ~DHCPCD_IPV4LL;
                break;
-       case 'B':
-               ifo->options &= ~DHCPCD_DAEMONISE;
-               break;
        case 'C':
                /* Commas to spaces for shell */
                while ((p = strchr(arg, ',')))
index 11753f46a5c16ae2e045f00d333873c0d3581d2b..6f67f41fd83b0ef06b279754093b6c10b4212798 100644 (file)
@@ -60,7 +60,7 @@
 #define DHCPCD_DAEMONISE       (1 << 14)
 #define DHCPCD_DAEMONISED      (1 << 15)
 #define DHCPCD_TEST            (1 << 16)
-#define DHCPCD_FORKED          (1 << 17)
+#define DHCPCD_MASTER          (1 << 17)
 #define DHCPCD_HOSTNAME                (1 << 18)
 #define DHCPCD_CLIENTID                (1 << 19)
 #define DHCPCD_LINK            (1 << 20)