]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1277. [bug] Failure to write pid-file should not be fatal on
authorMark Andrews <marka@isc.org>
Fri, 3 May 2002 05:28:29 +0000 (05:28 +0000)
committerMark Andrews <marka@isc.org>
Fri, 3 May 2002 05:28:29 +0000 (05:28 +0000)
                        reload. [RT #2861]

CHANGES
bin/named/include/named/main.h
bin/named/main.c
bin/named/server.c
bin/named/unix/include/named/os.h
bin/named/unix/os.c
bin/named/win32/include/named/os.h
bin/named/win32/os.c

diff --git a/CHANGES b/CHANGES
index 2e9c10653162e2b261afea16ebed60875ddac10d..22044f2e868687ac5b744b3f835bd67cfb9f01c3 100644 (file)
--- 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
index 3ff86f61f3578700aecb74199e4bef032dde3b8c..fb161f8e58e0546157b4b483614f213ce9d22fe9 100644 (file)
@@ -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 *);
 
index 4de89f2e0b7e574fec671cf2ae2993d367627420..8239bbc3ffaf04513c83eaac92c2437726512d48 100644 (file)
@@ -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 <config.h>
 
@@ -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;
 
index 5580ef7d864ea2d6c0528b0b47f4971a6c3241bf..87f211df9332d092b1aaaecd1aaa0c28072c3c3c 100644 (file)
@@ -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 <config.h>
 
@@ -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 &&
index 98f20459f7d6e1ce91eebec435fa762c182b83b3..b7e195172d6d2591858f3de720753a5a73fb4ba8 100644 (file)
@@ -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);
index 07319b0c2c2c3617d24a50cc8ff6b5e6241c8d70..548589c631ed15f0ca28493d1457c39eb9b799be 100644 (file)
@@ -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 <config.h>
 #include <stdarg.h>
@@ -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);
 }
 
index b731f5be98d0fe548bd390cab6013ebe0f7f01c4..7c8d407d4e0985a8a98c86bdba69526a2a681f92 100644 (file)
@@ -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);
index f79a41daf51c4bf7d1c4f978da24d284e6e3f7de..e551f153d15ffe972ddd3e56b2e0b8c5fd7c45a4 100644 (file)
@@ -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 <config.h>
 #include <stdarg.h>
@@ -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);
 }