]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add talloc memory report on -M
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 19 Feb 2013 00:33:04 +0000 (19:33 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 19 Feb 2013 21:13:05 +0000 (16:13 -0500)
src/include/radiusd.h
src/main/log.c
src/main/radiusd.c

index c4c379ce6e296536562790100ed3becf1fb77830..9513591e45d699ce47eb9d917de9011307cdddd6 100644 (file)
@@ -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
index c3ad41cd2b512e62bf4f9c34c8b6687752729edd..ac7f3d1b1c9e28810b8c64da65c0e3417ca97cc6 100644 (file)
@@ -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);
+}
index b376309c1ec8b40b42a52e98d3325bf93b7eee41..22df4133533c6b4de80778efffb41aa6ef4d48b1 100644 (file)
@@ -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;
                        }