diff --git a/bin/named/include/named/main.h b/bin/named/include/named/main.h index e0acafb031..3ff86f61f3 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.8 2001/08/08 22:54:26 gson Exp $ */ +/* $Id: main.h,v 1.9 2001/09/07 00:36:55 marka Exp $ */ #ifndef NAMED_MAIN_H #define NAMED_MAIN_H 1 @@ -23,4 +23,7 @@ void ns_main_earlyfatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); +void +ns_main_setmemstats(const char *); + #endif /* NAMED_MAIN_H */ diff --git a/bin/named/main.c b/bin/named/main.c index 7527817d4f..4bca550ede 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.121 2001/09/07 00:17:25 gson Exp $ */ +/* $Id: main.c,v 1.122 2001/09/07 00:36:52 marka Exp $ */ #include @@ -565,10 +565,28 @@ cleanup(void) { ns_log_shutdown(); } +static char *memstats = NULL; + +void +ns_main_setmemstats(const char *filename) { + /* + * Caller has to ensure locking. + */ + + if (memstats != NULL) { + free(memstats); + memstats = NULL; + } + if (filename == NULL) + return; + memstats = malloc(strlen(filename) + 1); + if (memstats) + strcpy(memstats, filename); +} + int main(int argc, char *argv[]) { isc_result_t result; - static const char *memstats; result = isc_file_progname(*argv, program_name, sizeof(program_name)); if (result != ISC_R_SUCCESS) @@ -627,8 +645,7 @@ main(int argc, char *argv[]) { isc_mem_stats(ns_g_mctx, stdout); isc_mutex_stats(stdout); } - memstats = ns_os_getmemstats(); - if (memstats) { + if (memstats != NULL) { FILE *fp = NULL; result = isc_stdio_open(memstats, "w", &fp); if (result == ISC_R_SUCCESS) { @@ -639,6 +656,8 @@ main(int argc, char *argv[]) { } isc_mem_destroy(&ns_g_mctx); + ns_main_setmemstats(NULL); + isc_app_finish(); ns_os_shutdown(); diff --git a/bin/named/server.c b/bin/named/server.c index 4762c02e0e..7dc6a15d61 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.341 2001/09/06 02:13:50 marka Exp $ */ +/* $Id: server.c,v 1.342 2001/09/07 00:36:54 marka Exp $ */ #include @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -2047,9 +2048,9 @@ load_configuration(const char *filename, ns_server_t *server, obj = NULL; if (options != NULL && cfg_map_get(options, "memstatistics-file", &obj) == ISC_R_SUCCESS) - ns_os_setmemstats(cfg_obj_asstring(obj)); + ns_main_setmemstats(cfg_obj_asstring(obj)); else - ns_os_setmemstats(NULL); + ns_main_setmemstats(NULL); obj = NULL; result = ns_config_get(maps, "statistics-file", &obj); diff --git a/bin/named/unix/include/named/os.h b/bin/named/unix/include/named/os.h index f3bc1a9c47..0373f6bd4f 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.15 2001/09/06 02:13:52 marka Exp $ */ +/* $Id: os.h,v 1.16 2001/09/07 00:36:59 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -43,12 +43,6 @@ ns_os_minprivs(void); void ns_os_writepidfile(const char *filename); -void -ns_os_setmemstats(const char *filename); - -const char * -ns_os_getmemstats(void); - void ns_os_shutdown(void); diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index bd59847be3..70976243fe 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.48 2001/09/06 02:13:51 marka Exp $ */ +/* $Id: os.c,v 1.49 2001/09/07 00:36:57 marka Exp $ */ #include #include @@ -43,7 +43,6 @@ #include static char *pidfile = NULL; -static char *memstats = NULL; /* * If there's no , we don't care about @@ -516,32 +515,8 @@ ns_os_writepidfile(const char *filename) { (void)fclose(lockfile); } -static inline void -cleanup_memstats(void) { - if (memstats != NULL) - free(memstats); - memstats = NULL; -} - -void -ns_os_setmemstats(const char *filename) { - - cleanup_memstats(); - if (filename == NULL) - return; - memstats = malloc(strlen(filename) + 1); - if (memstats) - strcpy(memstats, filename); -} - -const char * -ns_os_getmemstats(void) { - return (memstats); -} - void ns_os_shutdown(void) { closelog(); cleanup_pidfile(); - cleanup_memstats(); } diff --git a/bin/named/win32/include/named/os.h b/bin/named/win32/include/named/os.h index 6559ed5551..a042c2386f 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.2 2001/09/06 02:13:55 marka Exp $ */ +/* $Id: os.h,v 1.3 2001/09/07 00:37:02 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -43,12 +43,6 @@ ns_os_minprivs(void); void ns_os_writepidfile(const char *filename); -void -ns_os_setmemstats(const char *filename); - -const char * -ns_os_getmemstats(void); - void ns_os_shutdown(void); diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index cdf9d0068a..f1c66a07da 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.6 2001/09/06 02:13:54 marka Exp $ */ +/* $Id: os.c,v 1.7 2001/09/07 00:37:00 marka Exp $ */ #include #include @@ -43,7 +43,6 @@ static char *pidfile = NULL; -static char *memstats = NULL; static BOOL Initialized = FALSE; @@ -199,32 +198,9 @@ ns_os_writepidfile(const char *filename) { (void)fclose(lockfile); } -static inline -cleanup_memstats(void) { - if (memstats != NULL) - free(memstats); - memstats = NULL; -} - -void -ns_os_setmemstats(const char *filename) { - cleanup_memstats(); - if (filename == NULL) - return; - memstats = malloc(strlen(filename) + 1); - if (memstats != NULL) - strcpy(memstats, filename); -} - -const char * -ns_os_getmemstats(void) { - return (memstats); -} - void ns_os_shutdown(void) { closelog(); cleanup_pidfile(); - cleanup_memstats(); ntservice_shutdown(); /* This MUST be the last thing done */ }