Make squid reopen its logfiles upon a HUP

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

Hi,

The following diff (relative to 2.3.STABLE4) will make squid reopen its
logfiles whenever it is asked to reconfigure (SIGHUP). This is very useful
when squid's logs are managed by something like logrotate or newsyslog,
rather than squid's own log rotation. You may wish to allocate a differnet
signal to this action, but HUP is good enough for my needs.

I am not subscribed to the mailing list, so please Cc me on any
discussion.

Thanks,
Damien Miller

--- useragent.c.orig Fri Mar 22 10:41:03 2002
+++ useragent.c Fri Mar 22 10:41:06 2002
@@ -104,6 +104,23 @@
 }
 
 void
+useragentReopenLog(void)
+{
+#if USE_USERAGENT_LOG
+ if (Config.Log.useragent == NULL)
+ return;
+ if (strcmp(Config.Log.useragent, "none") == 0)
+ return;
+ if (cache_useragent_log) {
+ file_close(fileno(cache_useragent_log));
+ fclose(cache_useragent_log);
+ cache_useragent_log = NULL;
+ }
+ useragentOpenLog();
+#endif
+}
+
+void
 logUserAgent(const char *client, const char *agent)
 {
 #if USE_USERAGENT_LOG
--- main.c.orig Fri Mar 22 10:35:44 2002
+++ main.c Fri Mar 22 10:39:22 2002
@@ -384,6 +384,17 @@
 }
 
 static void
+mainReopen(void)
+{
+ icmpClose();
+ _db_reopen_log(); /* cache.log */
+ storeLogReopen(); /* store.log */
+ accessLogReopen(); /* access.log */
+ useragentReopenLog(); /* useragent.log */
+ icmpOpen();
+}
+
+static void
 setEffectiveUser(void)
 {
     leave_suid(); /* Run as non privilegied user */
@@ -670,6 +681,7 @@
     for (;;) {
         if (do_reconfigure) {
             mainReconfigure();
+ mainReopen();
             do_reconfigure = 0;
         } else if (do_rotate) {
             mainRotate();
--- access_log.c.orig Fri Mar 22 10:36:49 2002
+++ access_log.c Fri Mar 22 10:43:12 2002
@@ -362,6 +362,24 @@
 }
 
 void
+accessLogReopen(void)
+{
+#if FORW_VIA_DB
+ fvdbClear();
+#endif
+ if (LogfileName == NULL)
+ return;
+ file_close(LogfileFD); /* always close */
+ /* Reopen the log. It may have been renamed "manually" */
+ LogfileFD = file_open(LogfileName, O_WRONLY | O_CREAT);
+ if (LogfileFD == DISK_ERROR) {
+ debug(46, 0) ("accessLogRotate: Cannot open logfile: %s\n", LogfileName);
+ LogfileStatus = LOG_DISABLE;
+ fatalf("Cannot open %s: %s", LogfileName, xstrerror());
+ }
+}
+
+void
 accessLogClose(void)
 {
     file_close(LogfileFD);
--- store_log.c.orig Fri Mar 22 10:36:22 2002
+++ store_log.c Fri Mar 22 10:43:51 2002
@@ -128,6 +128,24 @@
 }
 
 void
+storeLogReopen(void)
+{
+ if (storelog_fd > -1) {
+ file_close(storelog_fd);
+ storelog_fd = -1;
+ }
+ if (Config.Log.store == NULL)
+ return;
+ if (strcmp(Config.Log.store, "none") == 0)
+ return;
+ storelog_fd = file_open(Config.Log.store, O_WRONLY | O_CREAT);
+ if (storelog_fd < 0) {
+ debug(50, 0) ("storeLogReopen: %s: %s\n", Config.Log.store, xstrerror());
+ debug(20, 1) ("Store logging disabled\n");
+ }
+}
+
+void
 storeLogClose(void)
 {
     if (storelog_fd >= 0)
--- protos.h.orig Fri Mar 22 10:35:57 2002
+++ protos.h Fri Mar 22 10:36:29 2002
@@ -33,6 +33,7 @@
 
 extern void accessLogLog(AccessLogEntry *);
 extern void accessLogRotate(void);
+extern void accessLogReopen(void);
 extern void accessLogClose(void);
 extern void accessLogInit(void);
 extern const char *accessLogTime(time_t);
@@ -200,6 +201,7 @@
 
 extern void _db_init(const char *logfile, const char *options);
 extern void _db_rotate_log(void);
+extern void _db_reopen_log(void);
 
 #if STDC_HEADERS
 extern void _db_print(const char *,...);
@@ -893,6 +895,7 @@
  */
 extern void storeLog(int tag, const StoreEntry * e);
 extern void storeLogRotate(void);
+extern void storeLogReopen(void);
 extern void storeLogClose(void);
 extern void storeLogOpen(void);
 
@@ -1067,6 +1070,7 @@
 
 extern void useragentOpenLog(void);
 extern void useragentRotateLog(void);
+extern void useragentReopenLog(void);
 extern void logUserAgent(const char *, const char *);
 extern peer_t parseNeighborType(const char *s);
 
--- debug.c.orig Fri Mar 22 10:35:53 2002
+++ debug.c Fri Mar 22 10:36:35 2002
@@ -225,6 +225,14 @@
         debugOpenLog(Config.Log.log);
 }
 
+void
+_db_reopen_log(void)
+{
+ /* Close and reopen the log. */
+ if (debug_log != stderr)
+ debugOpenLog(Config.Log.log);
+}
+
 static const char *
 debugLogTime(time_t t)
 {
Received on Thu Mar 21 2002 - 17:10:49 MST

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