/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
char fmt_cpy[1024];
#endif
+ /* If we're printing the pidfile, don't do anything. */
+ if (ctx != NULL && ctx->options & DHCPCD_PRINT_PIDFILE)
+ return;
+
serrno = errno;
va_start(va, fmt);
-.\" Copyright (c) 2006-2015 Roy Marples
+.\" Copyright (c) 2006-2016 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 22, 2015
+.Dd January 7, 2016
.Dt DHCPCD 8
.Os
.Sh NAME
.Nd a DHCP client
.Sh SYNOPSIS
.Nm
-.Op Fl 46ABbDdEGgHJKLMNpqTV
+.Op Fl 46ABbDdEGgHJKLMNPpqTV
.Op Fl C , Fl Fl nohook Ar hook
.Op Fl c , Fl Fl script Ar script
.Op Fl e , Fl Fl env Ar value
Removes the
.Ar option
from the DHCP message before processing.
+.It Fl P , Fl FL printpidfile
+Print the
+.Pa pidfile
+.Nm
+will use based on commmand-line arguments to stdout.
.It Fl Q , Fl Fl require Ar option
Requires the
.Ar option
usage(void)
{
-printf("usage: "PACKAGE"\t[-46ABbDdEGgHJKkLnpqTVw]\n"
+printf("usage: "PACKAGE"\t[-46ABbDdEGgHJKkLnPpqTVw]\n"
"\t\t[-C, --nohook hook] [-c, --script script]\n"
"\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n"
"\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n"
ctx.udp_fd = -1;
#endif
i = 0;
- while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
+ while ((opt = getopt_long(argc, argv,
+ ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
+ cf_options, &oi)) != -1)
{
switch (opt) {
case '4':
siga = "USR1";
break;
#endif
+ case 'P':
+ ctx.options |= DHCPCD_PRINT_PIDFILE;
+ break;
case 'T':
i = 1;
break;
i = 2;
break;
case '?':
+ if (ctx.options & DHCPCD_PRINT_PIDFILE)
+ continue;
usage();
goto exit_failure;
}
ctx.ifv = argv + optind;
ifo = read_config(&ctx, NULL, NULL, NULL);
- if (ifo == NULL)
+ if (ifo == NULL) {
+ if (ctx.options & DHCPCD_PRINT_PIDFILE)
+ goto printpidfile;
goto exit_failure;
+ }
opt = add_options(&ctx, NULL, ifo, argc, argv);
if (opt != 1) {
+ if (ctx.options & DHCPCD_PRINT_PIDFILE)
+ goto printpidfile;
if (opt == 0)
usage();
goto exit_failure;
#endif
goto exit_success;
}
- ctx.options = ifo->options;
+ ctx.options |= ifo->options;
if (i == 1 || i == 3) {
if (i == 1)
ctx.options |= DHCPCD_TEST;
if (ctx.options & DHCPCD_DEBUG)
logger_mask(&ctx, LOG_UPTO(LOG_DEBUG));
- if (ctx.options & DHCPCD_QUIET) {
- i = open(_PATH_DEVNULL, O_RDWR);
- if (i == -1)
- logger(&ctx, LOG_ERR, "%s: open: %m", __func__);
- else {
- dup2(i, STDERR_FILENO);
- close(i);
- }
- }
if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
+printpidfile:
/* If we have any other args, we should run as a single dhcpcd
* instance for that interface. */
if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) {
PIDFILE, "", "", "");
ctx.options |= DHCPCD_MASTER;
}
+ if (ctx.options & DHCPCD_PRINT_PIDFILE) {
+ printf("%s\n", ctx.pidfile);
+ goto exit_success;
+ }
}
if (chdir("/") == -1)
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
{"master", no_argument, NULL, 'M'},
{"renew", no_argument, NULL, 'N'},
{"nooption", required_argument, NULL, 'O'},
+ {"printpidfile", no_argument, NULL, 'P'},
{"require", required_argument, NULL, 'Q'},
{"static", required_argument, NULL, 'S'},
{"test", no_argument, NULL, 'T'},
case 'n': /* FALLTHROUGH */
case 'x': /* FALLTHROUGH */
case 'N': /* FALLTHROUGH */
+ case 'P': /* FALLTHROUGH */
case 'T': /* FALLTHROUGH */
case 'U': /* FALLTHROUGH */
case 'V': /* We need to handle non interface options */
* only use the dhcpcd.conf entry for that. */
if (ifname != NULL)
wait_opts = ifo->options & DHCPCD_WAITOPTS;
- while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
+ while ((opt = getopt_long(argc, argv,
+ ctx->options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
+ cf_options, &oi)) != -1)
{
r = parse_option(ctx, ifname, ifo, opt, optarg, NULL, NULL);
if (r != 1)
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
#define IF_OPTS "46bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
- "ABC:DEF:GHI:JKLMNO:Q:S:TUVW:X:Z:"
+ "ABC:DEF:GHI:JKLMNO:PQ:S:TUVW:X:Z:"
+#define NOERR_IF_OPTS ":" IF_OPTS
#define DEFAULT_TIMEOUT 30
#define DEFAULT_REBOOT 5
#define DHCPCD_IPV6RA_ACCEPT_NOPUBLIC (1ULL << 56)
#define DHCPCD_BOOTP (1ULL << 57)
#define DHCPCD_INITIAL_DELAY (1ULL << 58)
+#define DHCPCD_PRINT_PIDFILE (1ULL << 59)
#define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)