diff --git a/CHANGES b/CHANGES index 2e9c106531..22044f2e86 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1277. [bug] Failure to write pid-file should not be fatal on + reload. [RT #2861] + 1276. [contrib] 'queryperf' now has EDNS (-e) + DNSSEC DO (-D) support. 1275. [bug] When verifying that an NXT proves nonexistence, check diff --git a/bin/named/include/named/main.h b/bin/named/include/named/main.h index 3ff86f61f3..fb161f8e58 100644 --- a/bin/named/include/named/main.h +++ b/bin/named/include/named/main.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.h,v 1.9 2001/09/07 00:36:55 marka Exp $ */ +/* $Id: main.h,v 1.10 2002/05/03 05:28:23 marka Exp $ */ #ifndef NAMED_MAIN_H #define NAMED_MAIN_H 1 @@ -23,6 +23,9 @@ void ns_main_earlyfatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); +void +ns_main_earlywarning(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); + void ns_main_setmemstats(const char *); diff --git a/bin/named/main.c b/bin/named/main.c index 4de89f2e0b..8239bbc3ff 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.127 2002/03/13 23:36:14 bwelling Exp $ */ +/* $Id: main.c,v 1.128 2002/05/03 05:28:19 marka Exp $ */ #include @@ -70,10 +70,7 @@ static char program_name[ISC_DIR_NAMEMAX] = "named"; static char absolute_conffile[ISC_DIR_PATHMAX]; static char saved_command_line[512]; -static void -ns_main_earlywarning(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); - -static void +void ns_main_earlywarning(const char *format, ...) { va_list args; diff --git a/bin/named/server.c b/bin/named/server.c index 5580ef7d86..87f211df93 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.374 2002/04/26 00:40:24 marka Exp $ */ +/* $Id: server.c,v 1.375 2002/05/03 05:28:21 marka Exp $ */ #include @@ -1966,13 +1966,13 @@ load_configuration(const char *filename, ns_server_t *server, obj = NULL; if (ns_config_get(maps, "pid-file", &obj) == ISC_R_SUCCESS) if (cfg_obj_isvoid(obj)) - ns_os_writepidfile(NULL); + ns_os_writepidfile(NULL, first_time); else - ns_os_writepidfile(cfg_obj_asstring(obj)); + ns_os_writepidfile(cfg_obj_asstring(obj), first_time); else if (ns_g_lwresdonly) - ns_os_writepidfile(lwresd_g_defaultpidfile); + ns_os_writepidfile(lwresd_g_defaultpidfile, first_time); else - ns_os_writepidfile(ns_g_defaultpidfile); + ns_os_writepidfile(ns_g_defaultpidfile, first_time); obj = NULL; if (options != NULL && diff --git a/bin/named/unix/include/named/os.h b/bin/named/unix/include/named/os.h index 98f20459f7..b7e195172d 100644 --- a/bin/named/unix/include/named/os.h +++ b/bin/named/unix/include/named/os.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.h,v 1.18 2001/12/01 00:34:24 marka Exp $ */ +/* $Id: os.h,v 1.19 2002/05/03 05:28:26 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -41,7 +41,7 @@ void ns_os_minprivs(void); void -ns_os_writepidfile(const char *filename); +ns_os_writepidfile(const char *filename, isc_boolean_t first_time); void ns_os_shutdown(void); diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index 07319b0c2c..548589c631 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.c,v 1.57 2001/12/01 00:34:23 marka Exp $ */ +/* $Id: os.c,v 1.58 2002/05/03 05:28:25 marka Exp $ */ #include #include @@ -470,17 +470,20 @@ cleanup_pidfile(void) { } void -ns_os_writepidfile(const char *filename) { +ns_os_writepidfile(const char *filename, isc_boolean_t first_time) { int fd; FILE *lockfile; size_t len; pid_t pid; char strbuf[ISC_STRERRORSIZE]; + void (*report)(const char *, ...); /* * The caller must ensure any required synchronization. */ + report = first_time ? ns_main_earlyfatal : ns_main_earlywarning; + cleanup_pidfile(); if (filename == NULL) @@ -490,8 +493,8 @@ ns_os_writepidfile(const char *filename) { pidfile = malloc(len + 1); if (pidfile == NULL) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("couldn't malloc '%s': %s", - filename, strbuf); + (*report)("couldn't malloc '%s': %s", filename, strbuf); + return; } /* This is safe. */ strcpy(pidfile, filename); @@ -499,26 +502,37 @@ ns_os_writepidfile(const char *filename) { fd = safe_open(filename, ISC_FALSE); if (fd < 0) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("couldn't open pid file '%s': %s", - filename, strbuf); + (*report)("couldn't open pid file '%s': %s", filename, strbuf); + free(pidfile); + pidfile = NULL; + return; } lockfile = fdopen(fd, "w"); if (lockfile == NULL) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("could not fdopen() pid file '%s': %s", - filename, strbuf); + (*report)("could not fdopen() pid file '%s': %s", + filename, strbuf); + (void)close(fd); + cleanup_pidfile(); + return; } #ifdef HAVE_LINUXTHREADS pid = mainpid; #else pid = getpid(); #endif - if (fprintf(lockfile, "%ld\n", (long)pid) < 0) - ns_main_earlyfatal("fprintf() to pid file '%s' failed", - filename); - if (fflush(lockfile) == EOF) - ns_main_earlyfatal("fflush() to pid file '%s' failed", - filename); + if (fprintf(lockfile, "%ld\n", (long)pid) < 0) { + (*report)("fprintf() to pid file '%s' failed", filename); + (void)fclose(lockfile); + cleanup_pidfile(); + return; + } + if (fflush(lockfile) == EOF) { + (*report)("fflush() to pid file '%s' failed", filename); + (void)fclose(lockfile); + cleanup_pidfile(); + return; + } (void)fclose(lockfile); } diff --git a/bin/named/win32/include/named/os.h b/bin/named/win32/include/named/os.h index b731f5be98..7c8d407d4e 100644 --- a/bin/named/win32/include/named/os.h +++ b/bin/named/win32/include/named/os.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.h,v 1.5 2001/12/01 00:34:27 marka Exp $ */ +/* $Id: os.h,v 1.6 2002/05/03 05:28:29 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -41,7 +41,7 @@ void ns_os_minprivs(void); void -ns_os_writepidfile(const char *filename); +ns_os_writepidfile(const char *filename, isc_boolean_t first_time); void ns_os_shutdown(void); diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index f79a41daf5..e551f153d1 100644 --- a/bin/named/win32/os.c +++ b/bin/named/win32/os.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.c,v 1.13 2001/12/01 00:34:26 marka Exp $ */ +/* $Id: os.c,v 1.14 2002/05/03 05:28:27 marka Exp $ */ #include #include @@ -160,17 +160,20 @@ cleanup_pidfile(void) { } void -ns_os_writepidfile(const char *filename) { +ns_os_writepidfile(const char *filename, isc_boolean_t first_time) { int fd; FILE *lockfile; size_t len; pid_t pid; char strbuf[ISC_STRERRORSIZE]; + void (*report)(const char *, ...); /* * The caller must ensure any required synchronization. */ + report = first_time ? ns_main_earlyfatal : ns_main_earlywarning; + cleanup_pidfile(); if (strcmp(filename, "none") == 0) @@ -179,8 +182,8 @@ ns_os_writepidfile(const char *filename) { pidfile = malloc(len + 1); if (pidfile == NULL) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("couldn't malloc '%s': %s", - filename, strbuf); + (*report)("couldn't malloc '%s': %s", filename, strbuf); + return; } /* This is safe. */ strcpy(pidfile, filename); @@ -188,23 +191,35 @@ ns_os_writepidfile(const char *filename) { fd = safe_open(filename, ISC_FALSE); if (fd < 0) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("couldn't open pid file '%s': %s", - filename, strbuf); + (*report)("couldn't open pid file '%s': %s", filename, strbuf); + free(pidfile); + pidfile = NULL; + return; } lockfile = fdopen(fd, "w"); if (lockfile == NULL) { isc__strerror(errno, strbuf, sizeof(strbuf)); - ns_main_earlyfatal("could not fdopen() pid file '%s': %s", - filename, strbuf); + (*report)("could not fdopen() pid file '%s': %s", + filename, strbuf); + (void)close(fd); + cleanup_pidfile(); + return; } - pid = getpid(); - if (fprintf(lockfile, "%ld\n", (long)pid) < 0) - ns_main_earlyfatal("fprintf() to pid file '%s' failed", - filename); - if (fflush(lockfile) == EOF) - ns_main_earlyfatal("fflush() to pid file '%s' failed", - filename); + pid = getpid(); + + if (fprintf(lockfile, "%ld\n", (long)pid) < 0) { + (*report)("fprintf() to pid file '%s' failed", filename); + (void)fclose(fd); + cleanup_pidfile(); + return; + } + if (fflush(lockfile) == EOF) { + (*report)("fflush() to pid file '%s' failed", filename); + (void)fclose(fd); + cleanup_pidfile(); + return; + } (void)fclose(lockfile); }