From cf300e03de3df3ff422db922520bf07c686c86da Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Sat, 1 Dec 2001 00:34:27 +0000 Subject: [PATCH] 1153. [func] 'rndc {stop|halt} -p' now reports the process id of the instance of named being shutdown. --- CHANGES | 3 ++ bin/named/control.c | 5 +++- bin/named/unix/include/named/os.h | 5 +++- bin/named/unix/os.c | 48 +++++++++++++++++++++++++++++- bin/named/win32/include/named/os.h | 5 +++- bin/named/win32/os.c | 7 ++++- bin/rndc/rndc.c | 6 +++- 7 files changed, 73 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 94aef91542..d0fdb8d3ce 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1153. [func] 'rndc {stop|halt} -p' now reports the process id + of the instance of named being shutdown. + 1152. [bug] libbind: read buffer overflows. 1151. [bug] nslookup failed to check that the arguments to diff --git a/bin/named/control.c b/bin/named/control.c index a913c6a500..b32005891b 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: control.c,v 1.9 2001/11/27 04:06:08 marka Exp $ */ +/* $Id: control.c,v 1.10 2001/12/01 00:34:22 marka Exp $ */ #include @@ -32,6 +32,7 @@ #include #include +#include #include static isc_boolean_t @@ -89,10 +90,12 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { result = ns_server_retransfercommand(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_HALT)) { ns_server_flushonshutdown(ns_g_server, ISC_FALSE); + ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_STOP)) { ns_server_flushonshutdown(ns_g_server, ISC_TRUE); + ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) { diff --git a/bin/named/unix/include/named/os.h b/bin/named/unix/include/named/os.h index b52e7ccd89..98f20459f7 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.17 2001/10/08 07:46:08 marka Exp $ */ +/* $Id: os.h,v 1.18 2001/12/01 00:34:24 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -49,4 +49,7 @@ ns_os_shutdown(void); isc_result_t ns_os_gethostname(char *buf, size_t len); +void +ns_os_shutdownmsg(char *command, isc_buffer_t *text); + #endif /* NS_OS_H */ diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index 007e8237b4..07319b0c2c 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.56 2001/11/30 01:58:54 gson Exp $ */ +/* $Id: os.c,v 1.57 2001/12/01 00:34:23 marka Exp $ */ #include #include @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -535,3 +536,48 @@ ns_os_gethostname(char *buf, size_t len) { return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE); } +static char * +next_token(char **stringp, const char *delim) { + char *res; + + do { + res = strsep(stringp, delim); + if (res == NULL) + break; + } while (*res == '\0'); + return (res); +} + +void +ns_os_shutdownmsg(char *command, isc_buffer_t *text) { + char *input, *ptr; + unsigned int n; + pid_t pid; + + input = command; + + /* Skip the command name. */ + ptr = next_token(&input, " \t"); + if (ptr == NULL) + return; + + ptr = next_token(&input, " \t"); + if (ptr == NULL) + return; + + if (strcmp(ptr, "-p") != 0) + return; + +#ifdef HAVE_LINUXTHREADS + pid = mainpid; +#else + pid = getpid(); +#endif + + n = snprintf((char *)isc_buffer_used(text), + isc_buffer_availablelength(text), + "pid: %d", pid); + /* Only send a message if it is complete. */ + if (n < isc_buffer_availablelength(text)) + isc_buffer_add(text, n); +} diff --git a/bin/named/win32/include/named/os.h b/bin/named/win32/include/named/os.h index a134118928..b731f5be98 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.4 2001/10/08 07:46:11 marka Exp $ */ +/* $Id: os.h,v 1.5 2001/12/01 00:34:27 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -49,4 +49,7 @@ ns_os_shutdown(void); isc_result_t ns_os_gethostname(char *buf, size_t len); +void +ns_os_shutdownmsg(char *command, isc_buffer_t *text); + #endif /* NS_OS_H */ diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index d164106cd2..f79a41daf5 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.12 2001/11/22 03:11:01 mayer Exp $ */ +/* $Id: os.c,v 1.13 2001/12/01 00:34:26 marka Exp $ */ #include #include @@ -223,3 +223,8 @@ ns_os_gethostname(char *buf, size_t len) { return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE); } +void +ns_os_shutdownmsg(char *command, isc_buffer_t *text) { + UNUSED(command); + UNUSED(text); +} diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 6aad5f4f15..9516f37b09 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rndc.c,v 1.88 2001/11/30 02:09:48 gson Exp $ */ +/* $Id: rndc.c,v 1.89 2001/12/01 00:34:20 marka Exp $ */ /* * Principal Author: DCL @@ -100,7 +100,11 @@ command is one of the following:\n\ querylog Toggle query logging.\n\ dumpdb Dump cache(s) to the dump file (named_dump.db).\n\ stop Save pending updates to master files and stop the server.\n\ + stop -p Save pending updates to master files and stop the server\n\ + reporting process id.\n\ halt Stop the server without saving pending updates.\n\ + halt -p Stop the server without saving pending updates reporting\n\ + process id.\n\ trace Increment debugging level by one.\n\ trace level Change the debugging level.\n\ notrace Set debugging level to 0.\n\