debug: Do not constantly rename logs when max log size = 0
authorAndrew Bartlett <abartlet@samba.org>
Mon, 11 Jun 2012 03:22:42 +0000 (13:22 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 11 Jun 2012 11:34:43 +0000 (13:34 +0200)
In Samba4, the max log size parameter is not yet connected, so maxlog is 0

This means that we would, on receipt of a -HUP, have all child
processes attempt a rename.

Now we have the -HUP mean we reopen the logs unconditionally, and then
we see if the log is too large (samba3 mode) or simply proceed assuming
that someone else has renamed the logs for us.

Andrew Bartlett

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Mon Jun 11 13:34:43 CEST 2012 on sn-devel-104

lib/util/debug.c

index a990ad5112df6393d6ad88ead70f2c392f3e4952..15a2452b54e5908c0811310fcbc4e1dd0bb540f3 100644 (file)
@@ -688,25 +688,27 @@ void check_log_size( void )
 
        maxlog = state.settings.max_log_size * 1024;
 
-       if (state.schedule_reopen_logs ||
-          (fstat(state.fd, &st) == 0
+       if (state.schedule_reopen_logs) {
+           (void)reopen_logs_internal();
+       }
+
+       if (maxlog && (fstat(state.fd, &st) == 0
            && st.st_size > maxlog )) {
                (void)reopen_logs_internal();
-               if (state.fd > 0 && fstat(state.fd, &st) == 0) {
-                       if (st.st_size > maxlog) {
-                               char *name = NULL;
-
-                               if (asprintf(&name, "%s.old", state.debugf ) < 0) {
-                                       return;
-                               }
-                               (void)rename(state.debugf, name);
-
-                               if (!reopen_logs_internal()) {
-                                       /* We failed to reopen a log - continue using the old name. */
-                                       (void)rename(name, state.debugf);
-                               }
-                               SAFE_FREE(name);
+               if (state.fd > 2 && (fstat(state.fd, &st) == 0
+                                    && st.st_size > maxlog)) {
+                       char *name = NULL;
+                       
+                       if (asprintf(&name, "%s.old", state.debugf ) < 0) {
+                               return;
+                       }
+                       (void)rename(state.debugf, name);
+                       
+                       if (!reopen_logs_internal()) {
+                               /* We failed to reopen a log - continue using the old name. */
+                               (void)rename(name, state.debugf);
                        }
+                       SAFE_FREE(name);
                }
        }