From: Roy Marples Date: Fri, 5 Sep 2008 07:22:03 +0000 (+0000) Subject: Remove some ints and replace with our option mask. X-Git-Tag: v5.0.0~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da16617840a22827d78c99bab837d9be0a420c7c;p=thirdparty%2Fdhcpcd.git Remove some ints and replace with our option mask. --- diff --git a/bind.c b/bind.c index 6e7367fc..b0f7c9ba 100644 --- 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 f64d1c66..a8d6e3a8 100644 --- a/bind.h +++ b/bind.h @@ -35,6 +35,5 @@ pid_t daemonise(void); #endif -extern int can_daemonise; void bind_interface(void *); #endif diff --git a/dhcpcd.c b/dhcpcd.c index 658147e2..02315798 100644 --- 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 */ diff --git a/dhcpcd.h b/dhcpcd.h index 608a41d0..08605074 100644 --- 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 *); diff --git a/if-options.c b/if-options.c index f6f9140b..7d037a4e 100644 --- a/if-options.c +++ b/if-options.c @@ -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, ','))) diff --git a/if-options.h b/if-options.h index 11753f46..6f67f41f 100644 --- a/if-options.h +++ b/if-options.h @@ -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)