2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

ns_os_*memstats() -> ns_main_setmemstats()

This commit is contained in:
Mark Andrews
2001-09-07 00:37:02 +00:00
parent f56cdc894f
commit fe6b7ccc8d
7 changed files with 35 additions and 73 deletions

View File

@@ -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 */

View File

@@ -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 <config.h>
@@ -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();

View File

@@ -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 <config.h>
@@ -66,6 +66,7 @@
#include <named/log.h>
#include <named/logconf.h>
#include <named/lwresd.h>
#include <named/main.h>
#include <named/os.h>
#include <named/server.h>
#include <named/tkeyconf.h>
@@ -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);

View File

@@ -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);

View File

@@ -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 <config.h>
#include <stdarg.h>
@@ -43,7 +43,6 @@
#include <named/os.h>
static char *pidfile = NULL;
static char *memstats = NULL;
/*
* If there's no <linux/capability.h>, we don't care about <sys/prctl.h>
@@ -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();
}

View File

@@ -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);

View File

@@ -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 <config.h>
#include <stdarg.h>
@@ -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 */
}