/* 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;
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));
else
ifaces = iface->next;
free_interface(ifp);
- if (!master)
+ if (!(options & DHCPCD_MASTER))
exit(EXIT_FAILURE);
}
{
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;
}
}
+ 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;
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();
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
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");
exit(EXIT_FAILURE);
}
- if (!(ifo->options & DHCPCD_TEST)) {
+ if (!(options & DHCPCD_TEST)) {
if ((pid = read_pid()) > 0 &&
kill(pid, 0) == 0)
{
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);
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);
logger(LOG_ERR, "interface `%s' does not exist", ifv[0]);
exit(EXIT_FAILURE);
}
- if (background)
+ if (options & DHCPCD_BACKGROUND)
daemonise();
start_eloop();
/* NOTREACHED */
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,
}
*ifo->vendorclassid = (uint8_t)s;
break;
- case 'k':
- break;
case 'l':
if (*arg == '-') {
logger(LOG_ERR,
return -1;
}
break;
- case 'n':
- break;
case 'o':
if (make_option_mask(ifo->requestmask, arg, 1) != 0) {
logger(LOG_ERR, "unknown option `%s'", 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, ',')))