summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RELNOTES3
-rw-r--r--client/dhclient.c28
-rw-r--r--relay/dhcrelay.c4
-rw-r--r--server/dhcpd.c46
4 files changed, 63 insertions, 18 deletions
diff --git a/RELNOTES b/RELNOTES
index 70648978..7c99f43d 100644
--- a/RELNOTES
+++ b/RELNOTES
@@ -66,6 +66,9 @@ suggested fixes to <dhcp-users@isc.org>.
- Added -x option to dhclient, which triggers dhclient processes
to exit gracefully without releasing leases first
+- All binaries (client, server, relay) now change directories
+ to / before going into daemon mode, so as not to hold $CWD open
+
Changes since 4.0.0-20070413
- Old (expired) leases are now cleaned.
diff --git a/client/dhclient.c b/client/dhclient.c
index 5466af92..f05a94ef 100644
--- a/client/dhclient.c
+++ b/client/dhclient.c
@@ -32,7 +32,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhclient.c,v 1.152 2007/06/06 22:57:32 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.153 2007/06/07 15:29:30 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -276,7 +276,29 @@ main(int argc, char **argv) {
else
log_fatal("Impossible condition at %s:%d.", MDL);
- /* first kill of any currently running client */
+ /*
+ * convert relative path names to absolute, for files that need
+ * to be reopened after chdir() has been called
+ */
+ if (path_dhclient_db[0] != '/') {
+ char *path = dmalloc(PATH_MAX, MDL);
+ if (path == NULL)
+ log_fatal("No memory for filename\n");
+ path_dhclient_db = realpath(path_dhclient_db, path);
+ if (path_dhclient_db == NULL)
+ log_fatal("%s: %s", path, strerror(errno));
+ }
+
+ if (path_dhclient_script[0] != '/') {
+ char *path = dmalloc(PATH_MAX, MDL);
+ if (path == NULL)
+ log_fatal("No memory for filename\n");
+ path_dhclient_script = realpath(path_dhclient_script, path);
+ if (path_dhclient_script == NULL)
+ log_fatal("%s: %s", path, strerror(errno));
+ }
+
+ /* first kill off any currently running client */
if (release_mode || exit_mode) {
FILE *pidfd;
pid_t oldpid;
@@ -3049,6 +3071,8 @@ void go_daemon ()
open("/dev/null", O_RDWR);
write_client_pid_file ();
+
+ chdir("/");
}
void write_client_pid_file ()
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index d3bfbcce..96e0a97d 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -34,7 +34,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhcrelay.c,v 1.62 2007/05/19 19:16:26 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
+"$Id: dhcrelay.c,v 1.63 2007/06/07 15:29:31 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -312,6 +312,8 @@ main(int argc, char **argv) {
close (1);
close (2);
pid = setsid ();
+
+ chdir("/");
}
/* Start dispatching packets and timeouts... */
diff --git a/server/dhcpd.c b/server/dhcpd.c
index 59c3f9f9..913fe1f1 100644
--- a/server/dhcpd.c
+++ b/server/dhcpd.c
@@ -34,7 +34,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhcpd.c,v 1.126 2007/05/29 18:11:56 each Exp $ Copyright 2004-2007 Internet Systems Consortium.";
+"$Id: dhcpd.c,v 1.127 2007/06/07 15:29:31 each Exp $ Copyright 2004-2007 Internet Systems Consortium.";
#endif
static char copyright[] =
@@ -46,6 +46,7 @@ static char url [] = "For info, please visit http://www.isc.org/sw/dhcp/";
#include "dhcpd.h"
#include <omapip/omapip_p.h>
#include <syslog.h>
+#include <errno.h>
static void usage PROTO ((void));
@@ -378,6 +379,19 @@ main(int argc, char **argv) {
path_dhcpd_pid = s;
}
+ /*
+ * convert relative path names to absolute, for files that need
+ * to be reopened after chdir() has been called
+ */
+ if (path_dhcpd_db[0] != '/') {
+ char *path = dmalloc(PATH_MAX, MDL);
+ if (path == NULL)
+ log_fatal("No memory for filename\n");
+ path_dhcpd_db = realpath(path_dhcpd_db, path);
+ if (path_dhcpd_db == NULL)
+ log_fatal("%s: %s", path, strerror(errno));
+ }
+
if (!quiet) {
log_info("%s %s", message, PACKAGE_VERSION);
log_info (copyright);
@@ -638,6 +652,21 @@ main(int argc, char **argv) {
else
log_perror = 0;
+ /* If we didn't write the pid file earlier because we found a
+ process running the logged pid, but we made it to here,
+ meaning nothing is listening on the bootp port, then write
+ the pid file out - what's in it now is bogus anyway. */
+ if (!pidfilewritten) {
+ unlink (path_dhcpd_pid);
+ if ((i = open (path_dhcpd_pid,
+ O_WRONLY | O_CREAT, 0644)) >= 0) {
+ sprintf (pbuf, "%d\n", (int)getpid ());
+ write (i, pbuf, strlen (pbuf));
+ close (i);
+ pidfilewritten = 1;
+ }
+ }
+
if (daemon) {
/* Become session leader and get pid... */
pid = setsid();
@@ -652,21 +681,8 @@ main(int argc, char **argv) {
open("/dev/null", O_RDWR);
open("/dev/null", O_RDWR);
log_perror = 0; /* No sense logging to /dev/null. */
- }
- /* If we didn't write the pid file earlier because we found a
- process running the logged pid, but we made it to here,
- meaning nothing is listening on the bootp port, then write
- the pid file out - what's in it now is bogus anyway. */
- if (!pidfilewritten) {
- unlink (path_dhcpd_pid);
- if ((i = open (path_dhcpd_pid,
- O_WRONLY | O_CREAT, 0644)) >= 0) {
- sprintf (pbuf, "%d\n", (int)getpid ());
- write (i, pbuf, strlen (pbuf));
- close (i);
- pidfilewritten = 1;
- }
+ chdir("/");
}
#endif /* !DEBUG */