summaryrefslogtreecommitdiff
path: root/relay/dhcrelay.c
diff options
context:
space:
mode:
authorShawn Routhier <sar@isc.org>2011-04-15 21:58:12 +0000
committerShawn Routhier <sar@isc.org>2011-04-15 21:58:12 +0000
commit4a5bfeacbe463cb577f6edbf0143916847ea5feb (patch)
tree7cb9b6f08069c1f19b7b55a5a72d715bdc8a20ac /relay/dhcrelay.c
parentc7aa4dd4a4a3434f6f6ce017d2f4391882730049 (diff)
downloadisc-dhcp-4a5bfeacbe463cb577f6edbf0143916847ea5feb.tar.gz
Add the option "--no-pid" to the client, relay and server code,
to disable writing a pid file. Add the option "-pf pidfile" to the relay to allow the user to supply the pidfile name at runtime. Add the "with-relay6-pid-file" option to configure to allow the user to supply the pidfile name for the relay in v6 mode at configure time. [ISC-Bugs #23351] [ISC-Bugs #17541]
Diffstat (limited to 'relay/dhcrelay.c')
-rw-r--r--relay/dhcrelay.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index b127328a..62689fbc 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -3,7 +3,7 @@
DHCP/BOOTP Relay Agent. */
/*
- * Copyright(c) 2004-2009 by Internet Systems Consortium, Inc.("ISC")
+ * Copyright(c) 2004-2011 by Internet Systems Consortium, Inc.("ISC")
* Copyright(c) 1997-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
@@ -49,6 +49,9 @@ char *token_line;
char *tlname;
const char *path_dhcrelay_pid = _PATH_DHCRELAY_PID;
+isc_boolean_t no_dhcrelay_pid = ISC_FALSE;
+/* False (default) => we write and use a pid file */
+isc_boolean_t no_pid_file = ISC_FALSE;
int bogus_agent_drops = 0; /* Packets dropped because agent option
field was specified and we're not relaying
@@ -138,10 +141,12 @@ static const char url[] =
#define DHCRELAY_USAGE \
"Usage: dhcrelay [-4] [-d] [-q] [-a] [-D]\n"\
" [-A <length>] [-c <hops>] [-p <port>]\n" \
+" [-pf <pid-file>] [--no-pid]\n"\
" [-m append|replace|forward|discard]\n" \
" [-i interface0 [ ... -i interfaceN]\n" \
" server0 [ ... serverN]\n\n" \
" dhcrelay -6 [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \
+" [-pf <pid-file>] [--no-pid]\n"\
" -l lower0 [ ... -l lowerN]\n" \
" -u upper0 [ ... -u upperN]\n" \
" lower (client link): [address%%]interface[#index]\n" \
@@ -149,6 +154,7 @@ static const char url[] =
#else
#define DHCRELAY_USAGE \
"Usage: dhcrelay [-d] [-q] [-a] [-D] [-A <length>] [-c <hops>] [-p <port>]\n" \
+" [-pf <pid-file>] [--no-pid]\n"\
" [-m append|replace|forward|discard]\n" \
" [-i interface0 [ ... -i interfaceN]\n" \
" server0 [ ... serverN]\n\n"
@@ -350,6 +356,13 @@ main(int argc, char **argv) {
sl->next = upstreams;
upstreams = sl;
#endif
+ } else if (!strcmp(argv[i], "-pf")) {
+ if (++i == argc)
+ usage();
+ path_dhcrelay_pid = argv[i];
+ no_dhcrelay_pid = ISC_TRUE;
+ } else if (!strcmp(argv[i], "--no-pid")) {
+ no_pid_file = ISC_TRUE;
} else if (!strcmp(argv[i], "--version")) {
log_info("isc-dhcrelay-%s", PACKAGE_VERSION);
exit(0);
@@ -394,18 +407,24 @@ main(int argc, char **argv) {
}
}
- if (local_family == AF_INET) {
- path_dhcrelay_pid = getenv("PATH_DHCRELAY_PID");
- if (path_dhcrelay_pid == NULL)
- path_dhcrelay_pid = _PATH_DHCRELAY_PID;
- }
+ /*
+ * If the user didn't specify a pid file directly
+ * find one from environment variables or defaults
+ */
+ if (no_dhcrelay_pid == ISC_FALSE) {
+ if (local_family == AF_INET) {
+ path_dhcrelay_pid = getenv("PATH_DHCRELAY_PID");
+ if (path_dhcrelay_pid == NULL)
+ path_dhcrelay_pid = _PATH_DHCRELAY_PID;
+ }
#ifdef DHCPv6
- else {
- path_dhcrelay_pid = getenv("PATH_DHCRELAY6_PID");
- if (path_dhcrelay_pid == NULL)
- path_dhcrelay_pid = _PATH_DHCRELAY6_PID;
- }
+ else {
+ path_dhcrelay_pid = getenv("PATH_DHCRELAY6_PID");
+ if (path_dhcrelay_pid == NULL)
+ path_dhcrelay_pid = _PATH_DHCRELAY6_PID;
+ }
#endif
+ }
if (!quiet) {
log_info("%s %s", message, PACKAGE_VERSION);
@@ -519,20 +538,23 @@ main(int argc, char **argv) {
else if (pid)
exit(0);
- pfdesc = open(path_dhcrelay_pid,
- O_CREAT | O_TRUNC | O_WRONLY, 0644);
+ if (no_pid_file == ISC_FALSE) {
+ pfdesc = open(path_dhcrelay_pid,
+ O_CREAT | O_TRUNC | O_WRONLY, 0644);
- if (pfdesc < 0) {
- log_error("Can't create %s: %m", path_dhcrelay_pid);
- } else {
- pf = fdopen(pfdesc, "w");
- if (!pf)
- log_error("Can't fdopen %s: %m",
- path_dhcrelay_pid);
- else {
- fprintf(pf, "%ld\n",(long)getpid());
- fclose(pf);
- }
+ if (pfdesc < 0) {
+ log_error("Can't create %s: %m",
+ path_dhcrelay_pid);
+ } else {
+ pf = fdopen(pfdesc, "w");
+ if (!pf)
+ log_error("Can't fdopen %s: %m",
+ path_dhcrelay_pid);
+ else {
+ fprintf(pf, "%ld\n",(long)getpid());
+ fclose(pf);
+ }
+ }
}
close(0);