]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1733. [bug] Return non-zero exit status on initial load failure.
authorMark Andrews <marka@isc.org>
Wed, 29 Sep 2004 06:45:38 +0000 (06:45 +0000)
committerMark Andrews <marka@isc.org>
Wed, 29 Sep 2004 06:45:38 +0000 (06:45 +0000)
                        [RT #12658]

CHANGES
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 c3561e7f2c184810939241effbf1a2968db99d1d..710bb2332d29d0e7e8fcbf4876558259ed47df9e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,8 @@
 1734.  [cleanup]       'rndc-confgen -a -t' remove extra '/' in path.
                        [RT #12588]
 
-1733.  [placeholder]   rt12658
+1733.  [bug]           Return non-zero exit status on initial load failure.
+                       [RT #12658]
 
 1732.  [placeholder]   rt12467
 
index b642739b8c20febdca148952a47bdb308493c972..ac3683419b403624e7838bb09ae5a27fa52f9ae6 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: server.c,v 1.428 2004/06/18 04:38:45 marka Exp $ */
+/* $Id: server.c,v 1.429 2004/09/29 06:45:37 marka Exp $ */
 
 #include <config.h>
 
@@ -2805,7 +2805,7 @@ run_server(isc_task_t *task, isc_event_t *event) {
        isc_result_t result;
        ns_server_t *server = (ns_server_t *)event->ev_arg;
 
-       UNUSED(task);
+       INSIST(task == server->task);
 
        isc_event_free(&event);
 
@@ -2843,11 +2843,11 @@ run_server(isc_task_t *task, isc_event_t *event) {
 
        isc_hash_init();
 
-       CHECKFATAL(load_zones(server, ISC_FALSE),
-                  "loading zones");
+       CHECKFATAL(load_zones(server, ISC_FALSE), "loading zones");
 
+       ns_os_started();
        isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
-                     ISC_LOG_INFO, "running");
+                     ISC_LOG_NOTICE, "running");
 }
 
 void 
@@ -3187,8 +3187,7 @@ loadconfig(ns_server_t *server) {
        start_reserved_dispatches(server);
        result = load_configuration(ns_g_lwresdonly ?
                                    lwresd_g_conffile : ns_g_conffile,
-                                   server,
-                                   ISC_FALSE);
+                                   server, ISC_FALSE);
        if (result == ISC_R_SUCCESS)
                end_reserved_dispatches(server, ISC_FALSE);
        else
index 9e752842b9563a2257a7ca06390541df6bc118a5..874892ba62f627cd2356e39b54acf68544f2520d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.h,v 1.22 2004/03/05 04:58:05 marka Exp $ */
+/* $Id: os.h,v 1.23 2004/09/29 06:45:37 marka Exp $ */
 
 #ifndef NS_OS_H
 #define NS_OS_H 1
@@ -61,4 +61,7 @@ ns_os_shutdownmsg(char *command, isc_buffer_t *text);
 void
 ns_os_tzset(void);
 
+void
+ns_os_started(void);
+
 #endif /* NS_OS_H */
index 14b7f1955358d5bb42ac2fdc0fe8843016ff26d5..ec77a7f9ae73cb3660888945daddde1da56cf27c 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.69 2004/09/16 02:49:41 marka Exp $ */
+/* $Id: os.c,v 1.70 2004/09/29 06:45:37 marka Exp $ */
 
 #include <config.h>
 #include <stdarg.h>
@@ -104,6 +104,7 @@ static pid_t mainpid = 0;
 
 static struct passwd *runas_pw = NULL;
 static isc_boolean_t done_setuid = ISC_FALSE;
+static int dfd[2] = { -1, -1 };
 
 #ifdef HAVE_LINUX_CAPABILITY_H
 
@@ -305,13 +306,33 @@ ns_os_daemonize(void) {
        pid_t pid;
        char strbuf[ISC_STRERRORSIZE];
 
+       if (pipe(dfd) == -1) {
+               isc__strerror(errno, strbuf, sizeof(strbuf));
+               ns_main_earlyfatal("pipe(): %s", strbuf);
+       }
+
        pid = fork();
        if (pid == -1) {
                isc__strerror(errno, strbuf, sizeof(strbuf));
                ns_main_earlyfatal("fork(): %s", strbuf);
        }
-       if (pid != 0)
-               _exit(0);
+       if (pid != 0) {
+               int n;
+               /*
+                * Wait for the child to finish loading for the first time.
+                * This would be so much simpler if fork() worked once we
+                * were multi-threaded.
+                */
+               (void)close(dfd[1]);
+               do {
+                       char buf;
+                       n = read(dfd[0], &buf, 1);
+                       if (n == 1)
+                               _exit(0);
+               } while (n == -1 && errno == EINTR);
+               _exit(1);
+       }
+       (void)close(dfd[0]);
 
        /*
         * We're the child.
@@ -352,6 +373,20 @@ ns_os_daemonize(void) {
        }
 }
 
+void
+ns_os_started(void) {
+       char buf = 0;
+
+       /*
+        * Signal to the parent that we stated successfully.
+        */
+       if (dfd[0] != -1 && dfd[1] != -1) {
+               write(dfd[1], &buf, 1);
+               close(dfd[1]);
+               dfd[0] = dfd[1] = -1;
+       }
+}
+
 void
 ns_os_opendevnull(void) {
        devnullfd = open("/dev/null", O_RDWR, 0);
index c72a7f12ff0c762010c2ad870cbd26a881615df5..12e4ab4f6a3b0a46b8f6b46514c9085ca3503027 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.h,v 1.9 2004/03/05 04:58:11 marka Exp $ */
+/* $Id: os.h,v 1.10 2004/09/29 06:45:38 marka Exp $ */
 
 #ifndef NS_OS_H
 #define NS_OS_H 1
@@ -61,4 +61,7 @@ ns_os_shutdownmsg(char *command, isc_buffer_t *text);
 void
 ns_os_tzset(void);
 
+void
+ns_os_started(void);
+
 #endif /* NS_OS_H */
index 075c23ecd0646824a2075b2a783758198a3deb4f..6f8fa90716735a53c30374aaf0c3f42133a97a9e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.20 2004/03/05 04:58:08 marka Exp $ */
+/* $Id: os.c,v 1.21 2004/09/29 06:45:38 marka Exp $ */
 
 #include <config.h>
 #include <stdarg.h>
@@ -282,3 +282,7 @@ ns_os_tzset(void) {
        tzset();
 #endif
 }
+
+void
+ns_os_started(void) {
+}