From: Arran Cudbard-Bell Date: Tue, 19 Feb 2013 00:33:04 +0000 (-0500) Subject: Add talloc memory report on -M X-Git-Tag: release_3_0_0_beta1~1017 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=228ff628c91236c2969ca59962b8be0051cd5ca6;p=thirdparty%2Ffreeradius-server.git Add talloc memory report on -M --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index c4c379ce6e2..9513591e45d 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -471,6 +471,9 @@ typedef struct main_config_t { #define RDEBUG4 DEBUG4 #endif +void log_talloc(const char *message); +void log_talloc_report(TALLOC_CTX *ctx); + #define SECONDS_PER_DAY 86400 #define MAX_REQUEST_TIME 30 #define CLEANUP_DELAY 5 diff --git a/src/main/log.c b/src/main/log.c index c3ad41cd2b5..ac7f3d1b1c9 100644 --- a/src/main/log.c +++ b/src/main/log.c @@ -404,3 +404,26 @@ void radlog_request(int lvl, int priority, REQUEST *request, const char *msg, .. va_end(ap); } + +void log_talloc(const char *msg) +{ + radlog(L_INFO, "%s", msg); +} + +void log_talloc_report(TALLOC_CTX *ctx) +{ + struct main_config_t *myconfig = &mainconfig; + FILE *fd; + + fd = fdopen(myconfig->radlog_fd, "w"); + if (!fd) { + radlog(L_ERR, "Couldn't write memory report, fdopen failed: %s", + strerror(errno)); + + return; + } + radlog(L_INFO, "Allocated memory at time of report:"); + talloc_report_full(ctx, fd); + + fclose(fd); +} diff --git a/src/main/radiusd.c b/src/main/radiusd.c index b376309c1ec..22df4133533 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -64,6 +64,7 @@ const char *radlib_dir = NULL; int log_stripped_names; int debug_flag = 0; int check_config = FALSE; +int memory_report = FALSE; const char *radiusd_version = "FreeRADIUS Version " RADIUSD_VERSION_STRING #ifdef RADIUSD_VERSION_COMMIT @@ -150,7 +151,7 @@ int main(int argc, char *argv[]) mainconfig.log_file = NULL; /* Process the options. */ - while ((argval = getopt(argc, argv, "Cd:fhi:l:mn:p:stvxX")) != EOF) { + while ((argval = getopt(argc, argv, "Cd:fhi:l:mMn:p:stvxX")) != EOF) { switch(argval) { case 'C': @@ -203,6 +204,10 @@ int main(int argc, char *argv[]) debug_memory = 1; break; + case 'M': + memory_report = 1; + break; + case 'p': mainconfig.port = atoi(optarg); if ((mainconfig.port <= 0) || @@ -254,6 +259,11 @@ int main(int argc, char *argv[]) } } + if (memory_report) { + talloc_enable_null_tracking(); + talloc_set_log_fn(log_talloc); + } + /* * Mismatch between build time OpenSSL and linked SSL, * better to die here than segfault later. @@ -489,6 +499,10 @@ int main(int argc, char *argv[]) WSACleanup(); #endif + if (memory_report) { + log_talloc_report(NULL); + } + return (rcode - 1); } @@ -537,7 +551,7 @@ static void sig_fatal(int sig) #ifdef SIGQUIT case SIGQUIT: #endif - if (debug_memory) { + if (debug_memory || memory_report) { radius_signal_self(RADIUS_SIGNAL_SELF_TERM); break; }