DHCPCD(8): Add MASTER_ONLY option

This commit is contained in:
Sebastian Huber 2013-12-17 14:04:28 +01:00
parent 9cc83a74e2
commit 7758fcc11d

View File

@ -71,7 +71,9 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples";
struct if_head *ifaces = NULL; struct if_head *ifaces = NULL;
char vendor[VENDORCLASSID_MAX_LEN]; char vendor[VENDORCLASSID_MAX_LEN];
#ifndef MASTER_ONLY
int pidfd = -1; int pidfd = -1;
#endif
struct if_options *if_options = NULL; struct if_options *if_options = NULL;
int ifac = 0; int ifac = 0;
char **ifav = NULL; char **ifav = NULL;
@ -79,6 +81,7 @@ int ifdc = 0;
char **ifdv = NULL; char **ifdv = NULL;
sigset_t dhcpcd_sigset; sigset_t dhcpcd_sigset;
#ifndef MASTER_ONLY
const int handle_sigs[] = { const int handle_sigs[] = {
SIGALRM, SIGALRM,
SIGHUP, SIGHUP,
@ -88,15 +91,19 @@ const int handle_sigs[] = {
SIGUSR1, SIGUSR1,
0 0
}; };
#endif
static char *cffile; static char *cffile;
#ifndef MASTER_ONLY
static char *pidfile; static char *pidfile;
#endif
static int linkfd = -1; static int linkfd = -1;
static char **ifv; static char **ifv;
static int ifc; static int ifc;
static char **margv; static char **margv;
static int margc; static int margc;
#ifndef MASTER_ONLY
static pid_t static pid_t
read_pid(void) read_pid(void)
{ {
@ -112,6 +119,7 @@ read_pid(void)
fclose(fp); fclose(fp);
return pid; return pid;
} }
#endif
static void static void
usage(void) usage(void)
@ -136,6 +144,7 @@ printf("usage: "PACKAGE"\t[-46ABbDdEGgHJKkLnpqTVw]\n"
" "PACKAGE"\t-x, --exit [interface]\n"); " "PACKAGE"\t-x, --exit [interface]\n");
} }
#ifndef MASTER_ONLY
static void static void
free_globals(void) free_globals(void)
{ {
@ -204,6 +213,7 @@ cleanup(void)
if (options & DHCPCD_STARTED && !(options & DHCPCD_FORKED)) if (options & DHCPCD_STARTED && !(options & DHCPCD_FORKED))
syslog(LOG_INFO, "exited"); syslog(LOG_INFO, "exited");
} }
#endif /* !MASTER_ONLY */
/* ARGSUSED */ /* ARGSUSED */
static void static void
@ -830,6 +840,7 @@ reconf_reboot(int action, int argc, char **argv, int oi)
sort_interfaces(); sort_interfaces();
} }
#ifndef MASTER_ONLY
/* ARGSUSED */ /* ARGSUSED */
static void static void
sig_reboot(void *arg) sig_reboot(void *arg)
@ -927,6 +938,7 @@ handle_signal(int sig, siginfo_t *siginfo, __unused void *context)
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif /* MASTER_ONLY */
int int
handle_args(struct fd_list *fd, int argc, char **argv) handle_args(struct fd_list *fd, int argc, char **argv)
@ -1072,6 +1084,7 @@ handle_args(struct fd_list *fd, int argc, char **argv)
return 0; return 0;
} }
#ifndef MASTER_ONLY
static int static int
signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset) signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset)
{ {
@ -1094,6 +1107,7 @@ signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset)
} }
return 0; return 0;
} }
#endif
#ifdef __rtems__ #ifdef __rtems__
#include <rtems/libio.h> #include <rtems/libio.h>
@ -1119,10 +1133,13 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct interface *ifp; struct interface *ifp;
int opt, oi = 0, i;
#ifndef MASTER_ONLY
uint16_t family = 0; uint16_t family = 0;
int opt, oi = 0, sig = 0, i, control_fd; int sig = 0, control_fd;
size_t len; size_t len;
pid_t pid; pid_t pid;
#endif
struct timespec ts; struct timespec ts;
struct utsname utn; struct utsname utn;
const char *platform; const char *platform;
@ -1131,6 +1148,7 @@ main(int argc, char **argv)
openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON); openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_INFO)); setlogmask(LOG_UPTO(LOG_INFO));
#ifndef MASTER_ONLY
/* Test for --help and --version */ /* Test for --help and --version */
if (argc > 1) { if (argc > 1) {
if (strcmp(argv[1], "--help") == 0) { if (strcmp(argv[1], "--help") == 0) {
@ -1141,6 +1159,7 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
} }
#endif
platform = hardware_platform(); platform = hardware_platform();
if (uname(&utn) == 0) if (uname(&utn) == 0)
@ -1152,19 +1171,24 @@ main(int argc, char **argv)
snprintf(vendor, VENDORCLASSID_MAX_LEN, snprintf(vendor, VENDORCLASSID_MAX_LEN,
"%s-%s", PACKAGE, VERSION); "%s-%s", PACKAGE, VERSION);
#ifndef MASTER_ONLY
i = 0; i = 0;
#endif
while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
{ {
switch (opt) { switch (opt) {
#ifndef MASTER_ONLY
case '4': case '4':
family = AF_INET; family = AF_INET;
break; break;
case '6': case '6':
family = AF_INET6; family = AF_INET6;
break; break;
#endif
case 'f': case 'f':
cffile = optarg; cffile = optarg;
break; break;
#ifndef MASTER_ONLY
case 'g': case 'g':
sig = SIGUSR1; sig = SIGUSR1;
break; break;
@ -1186,6 +1210,7 @@ main(int argc, char **argv)
case 'V': case 'V':
i = 3; i = 3;
break; break;
#endif
case '?': case '?':
usage(); usage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1201,6 +1226,7 @@ main(int argc, char **argv)
usage(); usage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifndef MASTER_ONLY
if (i == 3) { if (i == 3) {
printf("Interface options:\n"); printf("Interface options:\n");
if_printoptions(); if_printoptions();
@ -1221,7 +1247,9 @@ main(int argc, char **argv)
#endif #endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#endif /* !MASTER_ONLY */
options = if_options->options; options = if_options->options;
#ifndef MASTER_ONLY
if (i != 0) { if (i != 0) {
if (i == 1) if (i == 1)
options |= DHCPCD_TEST; options |= DHCPCD_TEST;
@ -1230,6 +1258,7 @@ main(int argc, char **argv)
options |= DHCPCD_PERSISTENT; options |= DHCPCD_PERSISTENT;
options &= ~DHCPCD_DAEMONISE; options &= ~DHCPCD_DAEMONISE;
} }
#endif
#ifdef THERE_IS_NO_FORK #ifdef THERE_IS_NO_FORK
options &= ~DHCPCD_DAEMONISE; options &= ~DHCPCD_DAEMONISE;
@ -1237,6 +1266,7 @@ main(int argc, char **argv)
if (options & DHCPCD_DEBUG) if (options & DHCPCD_DEBUG)
setlogmask(LOG_UPTO(LOG_DEBUG)); setlogmask(LOG_UPTO(LOG_DEBUG));
#ifndef MASTER_ONLY
if (options & DHCPCD_QUIET) { if (options & DHCPCD_QUIET) {
i = open(_PATH_DEVNULL, O_RDWR); i = open(_PATH_DEVNULL, O_RDWR);
if (i == -1) if (i == -1)
@ -1263,9 +1293,13 @@ main(int argc, char **argv)
options |= DHCPCD_MASTER; options |= DHCPCD_MASTER;
} }
} }
#else
options |= DHCPCD_MASTER;
#endif
if (chdir("/") == -1) if (chdir("/") == -1)
syslog(LOG_ERR, "chdir `/': %m"); syslog(LOG_ERR, "chdir `/': %m");
#ifndef MASTER_ONLY
atexit(cleanup); atexit(cleanup);
if (options & DHCPCD_DUMPLEASE) { if (options & DHCPCD_DUMPLEASE) {
@ -1364,6 +1398,7 @@ main(int argc, char **argv)
writepid(pidfd, getpid()); writepid(pidfd, getpid());
} }
} }
#endif /* !MASTER_ONLY */
syslog(LOG_INFO, "version " VERSION " starting"); syslog(LOG_INFO, "version " VERSION " starting");
options |= DHCPCD_STARTED; options |= DHCPCD_STARTED;
@ -1372,6 +1407,7 @@ main(int argc, char **argv)
eloop_init(); eloop_init();
#endif #endif
#ifndef MASTER_ONLY
/* Save signal mask, block and redirect signals to our handler */ /* Save signal mask, block and redirect signals to our handler */
if (signal_init(handle_signal, &dhcpcd_sigset) == -1) { if (signal_init(handle_signal, &dhcpcd_sigset) == -1) {
syslog(LOG_ERR, "signal_setup: %m"); syslog(LOG_ERR, "signal_setup: %m");
@ -1382,6 +1418,7 @@ main(int argc, char **argv)
if (control_start() == -1) if (control_start() == -1)
syslog(LOG_ERR, "control_start: %m"); syslog(LOG_ERR, "control_start: %m");
} }
#endif
if (open_sockets() == -1) { if (open_sockets() == -1) {
syslog(LOG_ERR, "open_sockets: %m"); syslog(LOG_ERR, "open_sockets: %m");