diff --git a/CHANGES b/CHANGES index 76116a3a5f..9efe9a17fe 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ + 982. [func] If "memstatistics-file" is set in options the memory + statistics will be written to it. 981. [func] The dnssec tools can now take multiple '-r randomfile' arguments. diff --git a/bin/named/main.c b/bin/named/main.c index 2bb036fa43..c2bbbd7432 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.119 2001/08/08 22:54:20 gson Exp $ */ +/* $Id: main.c,v 1.120 2001/09/06 02:13:48 marka Exp $ */ #include @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -532,6 +533,7 @@ cleanup(void) { 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) @@ -590,6 +592,16 @@ main(int argc, char *argv[]) { isc_mem_stats(ns_g_mctx, stdout); isc_mutex_stats(stdout); } + memstats = ns_os_getmemstats(); + if (memstats) { + FILE *fp = NULL; + result = isc_stdio_open(memstats, "w", &fp); + if (result == ISC_R_SUCCESS) { + isc_mem_stats(ns_g_mctx, fp); + isc_mutex_stats(fp); + isc_stdio_close(fp); + } + } isc_mem_destroy(&ns_g_mctx); isc_app_finish(); diff --git a/bin/named/server.c b/bin/named/server.c index 5b86c640df..4762c02e0e 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.340 2001/08/30 05:52:12 marka Exp $ */ +/* $Id: server.c,v 1.341 2001/09/06 02:13:50 marka Exp $ */ #include @@ -2043,6 +2043,13 @@ load_configuration(const char *filename, ns_server_t *server, ns_os_writepidfile(lwresd_g_defaultpidfile); else ns_os_writepidfile(ns_g_defaultpidfile); + + obj = NULL; + if (options != NULL && + cfg_map_get(options, "memstatistics-file", &obj) == ISC_R_SUCCESS) + ns_os_setmemstats(cfg_obj_asstring(obj)); + else + ns_os_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 7f87b3cd30..f3bc1a9c47 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.14 2001/01/09 21:40:39 bwelling Exp $ */ +/* $Id: os.h,v 1.15 2001/09/06 02:13:52 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -43,6 +43,12 @@ 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 f470fa7f26..bd59847be3 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.47 2001/08/31 05:57:45 marka Exp $ */ +/* $Id: os.c,v 1.48 2001/09/06 02:13:51 marka Exp $ */ #include #include @@ -43,6 +43,7 @@ #include static char *pidfile = NULL; +static char *memstats = NULL; /* * If there's no , we don't care about @@ -515,8 +516,32 @@ 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 12a46c1c5b..6559ed5551 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.1 2001/07/18 03:43:18 mayer Exp $ */ +/* $Id: os.h,v 1.2 2001/09/06 02:13:55 marka Exp $ */ #ifndef NS_OS_H #define NS_OS_H 1 @@ -43,6 +43,12 @@ 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 a5ddef38b7..cdf9d0068a 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.5 2001/08/09 23:44:13 mayer Exp $ */ +/* $Id: os.c,v 1.6 2001/09/06 02:13:54 marka Exp $ */ #include #include @@ -43,6 +43,7 @@ static char *pidfile = NULL; +static char *memstats = NULL; static BOOL Initialized = FALSE; @@ -198,9 +199,32 @@ 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 */ }