Re: Make squid reopen its logfiles upon a HUP

From: Damien Miller <djm@dont-contact.us>
Date: Fri, 22 Mar 2002 16:57:28 +1100 (EST)

On Fri, 22 Mar 2002, Henrik Nordstrom wrote:

> The authoriative Squid documentation is squid.conf.default, and there
> the following is said:

[snip]

> and several references that you should be using "squid -k rotate" and
> "logfile_rotate" to control your logfile rotation
>
> 6.13. Which log files can I delete safely?
> 6.15. My log files get very big!
> 6.16. Managing log files
>
> Do we really need more?

I would expect this information to be in section 6.16, at least that is
where I first looked. None of the sections under log files section of the
manual mentioned this trick.

Obviously I didn't look as hard as I might have, but my presumption was
that since squid did its own logrotation, this feature hadn't been
implemented. This presumption seems to be fairly widespread, certainly
Redhat's squid logrotate script doesn't use this technique.

> But still, we need something in the spirit of your patch. When Squid is
> reconfigured it should reopen the logs and restart helpers to ensure the
> new configuration is reflected but I would prefer if it is done
> similarly to how if is done when rotating the logs rather than a second
> approach, except for the actual rotation.

Like this? (tested with a compile only)

-d

diff -ru squid-2.3.STABLE4-orig/src/access_log.c squid-2.3.STABLE4/src/access_log.c
--- squid-2.3.STABLE4-orig/src/access_log.c Tue Mar 14 17:48:22 2000
+++ squid-2.3.STABLE4/src/access_log.c Fri Mar 22 16:46:58 2002
@@ -321,7 +321,7 @@
 }
 
 void
-accessLogRotate(void)
+accessLogRotate(int reopen)
 {
     int i;
     LOCAL_ARRAY(char, from, MAXPATHLEN);
@@ -340,7 +340,7 @@
 #endif
     debug(46, 1) ("accessLogRotate: Rotating\n");
     /* Rotate numbers 0 through N up one */
- for (i = Config.Log.rotateNumber; i > 1;) {
+ for (i = reopen ? 0 : Config.Log.rotateNumber; i > 1;) {
         i--;
         snprintf(from, MAXPATHLEN, "%s.%d", fname, i - 1);
         snprintf(to, MAXPATHLEN, "%s.%d", fname, i);
@@ -348,7 +348,7 @@
     }
     /* Rotate the current log to .0 */
     file_close(LogfileFD); /* always close */
- if (Config.Log.rotateNumber > 0) {
+ if (!reopen && Config.Log.rotateNumber > 0) {
         snprintf(to, MAXPATHLEN, "%s.%d", fname, 0);
         xrename(fname, to);
     }
diff -ru squid-2.3.STABLE4-orig/src/debug.c squid-2.3.STABLE4/src/debug.c
--- squid-2.3.STABLE4-orig/src/debug.c Thu Feb 10 10:29:55 2000
+++ squid-2.3.STABLE4/src/debug.c Fri Mar 22 16:47:46 2002
@@ -185,7 +185,7 @@
 }
 
 void
-_db_rotate_log(void)
+_db_rotate_log(int reopen)
 {
     int i;
     LOCAL_ARRAY(char, from, MAXPATHLEN);
@@ -208,14 +208,14 @@
      * used everywhere debug.c is used.
      */
     /* Rotate numbers 0 through N up one */
- for (i = Config.Log.rotateNumber; i > 1;) {
+ for (i = reopen ? 0 : Config.Log.rotateNumber; i > 1;) {
         i--;
         snprintf(from, MAXPATHLEN, "%s.%d", debug_log_file, i - 1);
         snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, i);
         rename(from, to);
     }
     /* Rotate the current log to .0 */
- if (Config.Log.rotateNumber > 0) {
+ if (!reopen && Config.Log.rotateNumber > 0) {
         snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, 0);
         rename(debug_log_file, to);
     }
diff -ru squid-2.3.STABLE4-orig/src/main.c squid-2.3.STABLE4/src/main.c
--- squid-2.3.STABLE4-orig/src/main.c Thu Feb 10 10:29:58 2000
+++ squid-2.3.STABLE4/src/main.c Fri Mar 22 16:49:12 2002
@@ -51,7 +51,7 @@
 static volatile int do_rotate = 0;
 static volatile int do_shutdown = 0;
 
-static void mainRotate(void);
+static void mainRotate(int reopen);
 static void mainReconfigure(void);
 static SIGHDLR rotate_logs;
 static SIGHDLR reconfigure;
@@ -372,14 +372,14 @@
 }
 
 static void
-mainRotate(void)
+mainRotate(int reopen)
 {
     icmpClose();
- _db_rotate_log(); /* cache.log */
+ _db_rotate_log(reopen); /* cache.log */
     storeDirWriteCleanLogs(1);
- storeLogRotate(); /* store.log */
- accessLogRotate(); /* access.log */
- useragentRotateLog(); /* useragent.log */
+ storeLogRotate(reopen); /* store.log */
+ accessLogRotate(reopen); /* access.log */
+ useragentRotateLog(reopen); /* useragent.log */
     icmpOpen();
 }
 
@@ -670,9 +670,10 @@
     for (;;) {
         if (do_reconfigure) {
             mainReconfigure();
+ mainRotate(1);
             do_reconfigure = 0;
         } else if (do_rotate) {
- mainRotate();
+ mainRotate(0);
             do_rotate = 0;
         } else if (do_shutdown) {
             time_t wait = do_shutdown > 0 ? (int) Config.shutdownLifetime : 0;
diff -ru squid-2.3.STABLE4-orig/src/protos.h squid-2.3.STABLE4/src/protos.h
--- squid-2.3.STABLE4-orig/src/protos.h Sat Apr 8 06:32:30 2000
+++ squid-2.3.STABLE4/src/protos.h Fri Mar 22 16:45:20 2002
@@ -32,7 +32,7 @@
  */
 
 extern void accessLogLog(AccessLogEntry *);
-extern void accessLogRotate(void);
+extern void accessLogRotate(int reopen);
 extern void accessLogClose(void);
 extern void accessLogInit(void);
 extern const char *accessLogTime(time_t);
@@ -199,7 +199,7 @@
 extern void ctx_exit(Ctx ctx);
 
 extern void _db_init(const char *logfile, const char *options);
-extern void _db_rotate_log(void);
+extern void _db_rotate_log(int reopen);
 
 #if STDC_HEADERS
 extern void _db_print(const char *,...);
@@ -892,7 +892,7 @@
  * store_log.c
  */
 extern void storeLog(int tag, const StoreEntry * e);
-extern void storeLogRotate(void);
+extern void storeLogRotate(int reopen);
 extern void storeLogClose(void);
 extern void storeLogOpen(void);
 
@@ -1066,7 +1066,7 @@
 extern char *urlHostname(const char *url);
 
 extern void useragentOpenLog(void);
-extern void useragentRotateLog(void);
+extern void useragentRotateLog(int reopen);
 extern void logUserAgent(const char *, const char *);
 extern peer_t parseNeighborType(const char *s);
 
diff -ru squid-2.3.STABLE4-orig/src/store_log.c squid-2.3.STABLE4/src/store_log.c
--- squid-2.3.STABLE4-orig/src/store_log.c Thu Feb 10 10:30:03 2000
+++ squid-2.3.STABLE4/src/store_log.c Fri Mar 22 16:47:24 2002
@@ -82,7 +82,7 @@
 }
 
 void
-storeLogRotate(void)
+storeLogRotate(int reopen)
 {
     char *fname = NULL;
     int i;
@@ -109,14 +109,14 @@
     debug(20, 1) ("storeLogRotate: Rotating.\n");
 
     /* Rotate numbers 0 through N up one */
- for (i = Config.Log.rotateNumber; i > 1;) {
+ for (i = reopen ? 0 : Config.Log.rotateNumber; i > 1;) {
         i--;
         snprintf(from, MAXPATHLEN, "%s.%d", fname, i - 1);
         snprintf(to, MAXPATHLEN, "%s.%d", fname, i);
         xrename(from, to);
     }
     /* Rotate the current log to .0 */
- if (Config.Log.rotateNumber > 0) {
+ if (!reopen && Config.Log.rotateNumber > 0) {
         snprintf(to, MAXPATHLEN, "%s.%d", fname, 0);
         xrename(fname, to);
     }
diff -ru squid-2.3.STABLE4-orig/src/useragent.c squid-2.3.STABLE4/src/useragent.c
--- squid-2.3.STABLE4-orig/src/useragent.c Thu Feb 10 10:30:04 2000
+++ squid-2.3.STABLE4/src/useragent.c Fri Mar 22 16:46:18 2002
@@ -64,7 +64,7 @@
 }
 
 void
-useragentRotateLog(void)
+useragentRotateLog(int reopen)
 {
 #if USE_USERAGENT_LOG
     char *fname = NULL;
@@ -83,7 +83,7 @@
 #endif
     debug(40, 1) ("useragentRotateLog: Rotating.\n");
     /* Rotate numbers 0 through N up one */
- for (i = Config.Log.rotateNumber; i > 1;) {
+ for (i = reopen ? 0 : Config.Log.rotateNumber; i > 1;) {
         i--;
         snprintf(from, MAXPATHLEN, "%s.%d", fname, i - 1);
         snprintf(to, MAXPATHLEN, "%s.%d", fname, i);
@@ -95,7 +95,7 @@
         cache_useragent_log = NULL;
     }
     /* Rotate the current log to .0 */
- if (Config.Log.rotateNumber > 0) {
+ if (!reopen && Config.Log.rotateNumber > 0) {
         snprintf(to, MAXPATHLEN, "%s.%d", fname, 0);
         xrename(fname, to);
     }
Received on Fri Mar 22 2002 - 02:17:39 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:53 MST