From bafe87e2781012271085ca71ed4cd5ea7bc797bf Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 29 Sep 2004 06:43:54 +0000 Subject: [PATCH] 1733. [bug] Return non-zero exit status on initial load failure. [RT #12658] --- CHANGES | 3 +++ bin/named/server.c | 13 +++++----- bin/named/unix/include/named/os.h | 5 +++- bin/named/unix/os.c | 41 +++++++++++++++++++++++++++--- bin/named/win32/include/named/os.h | 5 +++- bin/named/win32/os.c | 6 ++++- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index ef5de21f19..19b0b5a845 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ 1734. [cleanup] 'rndc-confgen -a -t' remove extra '/' in path. [RT #12588] +1733. [bug] Return non-zero exit status on initial load failure. + [RT #12658] + 1726. [port] aix5: add support for aix5. 1723. [cleanup] Silence compiler warnings from t_tasks.c. [RT #12493] diff --git a/bin/named/server.c b/bin/named/server.c index 00874e96f3..3f7663df6a 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.419.18.9 2004/06/18 04:39:39 marka Exp $ */ +/* $Id: server.c,v 1.419.18.10 2004/09/29 06:43:53 marka Exp $ */ #include @@ -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 diff --git a/bin/named/unix/include/named/os.h b/bin/named/unix/include/named/os.h index 9e752842b9..8cdb6974db 100644 --- a/bin/named/unix/include/named/os.h +++ b/bin/named/unix/include/named/os.h @@ -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.22.18.1 2004/09/29 06:43:54 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 */ diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index 10d447f3e5..0425f7a38c 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.c,v 1.66.18.3 2004/09/16 02:49:50 marka Exp $ */ +/* $Id: os.c,v 1.66.18.4 2004/09/29 06:43:53 marka Exp $ */ #include #include @@ -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); diff --git a/bin/named/win32/include/named/os.h b/bin/named/win32/include/named/os.h index c72a7f12ff..17751abcc5 100644 --- a/bin/named/win32/include/named/os.h +++ b/bin/named/win32/include/named/os.h @@ -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.9.18.1 2004/09/29 06:43:54 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 */ diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index 075c23ecd0..a6d8f94121 100644 --- a/bin/named/win32/os.c +++ b/bin/named/win32/os.c @@ -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.20.18.1 2004/09/29 06:43:54 marka Exp $ */ #include #include @@ -255,6 +255,10 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) { (void)fclose(lockfile); } +void +ns_os_started(void) { +} + void ns_os_shutdown(void) { closelog();