]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1227: squid should syslog to daemon facility not local4
authorserassio <>
Thu, 7 Apr 2005 00:44:25 +0000 (00:44 +0000)
committerserassio <>
Thu, 7 Apr 2005 00:44:25 +0000 (00:44 +0000)
  this patch adds a new command line option -l to specify the syslog
  facility.

Forward port of 2.5 patch.

src/debug.cc
src/main.cc
src/protos.h

index 7b23d563c7b0291f9e7c984e0f8f34ad16b76b4d..6d4f481776d3b7cd96407dcaf0f3e509a9069344 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: debug.cc,v 1.96 2003/08/31 21:20:08 robertc Exp $
+ * $Id: debug.cc,v 1.97 2005/04/06 18:44:25 serassio Exp $
  *
  * DEBUG: section 0     Debug Routines
  * AUTHOR: Harvest Derived
@@ -45,6 +45,9 @@ static int Ctx_Lock = 0;
 static const char *debugLogTime(void);
 static void ctx_print(void);
 #if HAVE_SYSLOG
+#ifdef LOG_LOCAL4
+static int syslog_facility = 0;
+#endif
 static void _db_print_syslog(const char *format, va_list args);
 #endif
 static void _db_print_stderr(const char *format, va_list args);
@@ -231,6 +234,159 @@ debugOpenLog(const char *logfile) {
 #endif
 }
 
+#if HAVE_SYSLOG
+#ifdef LOG_LOCAL4
+
+static struct syslog_facility_name {
+    const char *name;
+    int facility;
+}
+
+syslog_facility_names[] = {
+
+#ifdef LOG_AUTH
+                              {
+                                  "auth", LOG_AUTH
+                              },
+#endif
+#ifdef LOG_AUTHPRIV
+                              {
+                                  "authpriv", LOG_AUTHPRIV
+                              },
+#endif
+#ifdef LOG_CRON
+                              {
+                                  "cron", LOG_CRON
+                              },
+#endif
+#ifdef LOG_DAEMON
+                              {
+                                  "daemon", LOG_DAEMON
+                              },
+#endif
+#ifdef LOG_FTP
+                              {
+                                  "ftp", LOG_FTP
+                              },
+#endif
+#ifdef LOG_KERN
+                              {
+                                  "kern", LOG_KERN
+                              },
+#endif
+#ifdef LOG_LPR
+                              {
+                                  "lpr", LOG_LPR
+                              },
+#endif
+#ifdef LOG_MAIL
+                              {
+                                  "mail", LOG_MAIL
+                              },
+#endif
+#ifdef LOG_NEWS
+                              {
+                                  "news", LOG_NEWS
+                              },
+#endif
+#ifdef LOG_SYSLOG
+                              {
+                                  "syslog", LOG_SYSLOG
+                              },
+#endif
+#ifdef LOG_USER
+                              {
+                                  "user", LOG_USER
+                              },
+#endif
+#ifdef LOG_UUCP
+                              {
+                                  "uucp", LOG_UUCP
+                              },
+#endif
+#ifdef LOG_LOCAL0
+                              {
+                                  "local0", LOG_LOCAL0
+                              },
+#endif
+#ifdef LOG_LOCAL1
+                              {
+                                  "local1", LOG_LOCAL1
+                              },
+#endif
+#ifdef LOG_LOCAL2
+                              {
+                                  "local2", LOG_LOCAL2
+                              },
+#endif
+#ifdef LOG_LOCAL3
+                              {
+                                  "local3", LOG_LOCAL3
+                              },
+#endif
+#ifdef LOG_LOCAL4
+                              {
+                                  "local4", LOG_LOCAL4
+                              },
+#endif
+#ifdef LOG_LOCAL5
+                              {
+                                  "local5", LOG_LOCAL5
+                              },
+#endif
+#ifdef LOG_LOCAL6
+                              {
+                                  "local6", LOG_LOCAL6
+                              },
+#endif
+#ifdef LOG_LOCAL7
+                              {
+                                  "local7", LOG_LOCAL7
+                              },
+#endif
+                              {
+                                  NULL, 0
+                              }
+                          };
+
+#endif
+
+void
+_db_set_syslog(const char *facility) {
+    opt_syslog_enable = 1;
+#ifdef LOG_LOCAL4
+#ifdef LOG_DAEMON
+
+    syslog_facility = LOG_DAEMON;
+#else
+
+    syslog_facility = LOG_LOCAL4;
+#endif
+
+    if (facility) {
+
+        struct syslog_facility_name *n;
+
+        for (n = syslog_facility_names; n->name; n++) {
+            if (strcmp(n->name, facility) == 0) {
+                syslog_facility = n->facility;
+                return;
+            }
+        }
+
+        fprintf(stderr, "unknown syslog facility '%s'\n", facility);
+        exit(1);
+    }
+
+#else
+    if (facility)
+        fprintf(stderr, "syslog facility type not supported on your system\n");
+
+#endif
+}
+
+#endif
+
 void
 Debug::parseOptions(char const *options) {
     int i;
@@ -259,7 +415,7 @@ _db_init(const char *logfile, const char *options) {
 #if HAVE_SYSLOG && defined(LOG_LOCAL4)
 
     if (opt_syslog_enable)
-        openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
+        openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, syslog_facility);
 
 #endif /* HAVE_SYSLOG */
 
index 0ab3a9e30b0613d5ada9290a8d6d7c8d3e67879a..56c303f63f0081086b2ec4af7cfe68d1d3e85764 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: main.cc,v 1.406 2005/04/03 17:11:21 serassio Exp $
+ * $Id: main.cc,v 1.407 2005/04/06 18:44:25 serassio Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -67,6 +67,7 @@ SQUIDCEXTERN void (*failure_notify) (const char *);
 
 static int opt_send_signal = -1;
 static int opt_parse_cfg_only = 0;
+static char *opt_syslog_facility = NULL;
 static int icpPortNumOverride = 1;     /* Want to detect "-u 0" */
 static int configured_once = 0;
 #if MALLOC_DBG
@@ -106,9 +107,9 @@ usage(void)
 {
     fprintf(stderr,
 #if USE_WIN32_SERVICE
-            "Usage: %s [-cdhirsvzCDFNRVYX] [-f config-file] [-[au] port] [-k signal] [-n name] [-O CommandLine]\n"
+            "Usage: %s [-cdhirvzCDFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal] [-n name] [-O CommandLine]\n"
 #else
-            "Usage: %s [-cdhsvzCDFNRVYX] [-f config-file] [-[au] port] [-k signal]\n"
+            "Usage: %s [-cdhvzCDFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]\n"
 #endif
             "       -a port   Specify HTTP port number (default: %d).\n"
             "       -d level  Write debugging to stderr also.\n"
@@ -126,7 +127,8 @@ usage(void)
             "                 default is: " _WIN_SQUID_DEFAULT_SERVICE_NAME ".\n"
             "       -r        Removes a Windows Service (see -n option).\n"
 #endif
-            "       -s        Enable logging to syslog.\n"
+            "       -s | -l facility\n"
+            "                 Enable logging to syslog.\n"
             "       -u port   Specify ICP port number (default: %d), disable with 0.\n"
             "       -v        Print version.\n"
             "       -z        Create swap directories\n"
@@ -155,10 +157,10 @@ mainParseOptions(int argc, char *argv[])
 
 #if USE_WIN32_SERVICE
 
-    while ((c = getopt(argc, argv, "CDFNO:RSVYXa:d:f:hik:m::n:rsu:vz?")) != -1)
+    while ((c = getopt(argc, argv, "CDFNO:RSVYXa:d:f:hik:m::n:rsl:u:vz?")) != -1)
 #else
 
-    while ((c = getopt(argc, argv, "CDFNRSVYXa:d:f:hk:m::su:vz?")) != -1)
+    while ((c = getopt(argc, argv, "CDFNRSVYXa:d:f:hk:m::sl:u:vz?")) != -1)
 #endif
 
     {
@@ -339,10 +341,13 @@ mainParseOptions(int argc, char *argv[])
 
 #endif
 
+        case 'l':
+            opt_syslog_facility = xstrdup(optarg);
+
         case 's':
 #if HAVE_SYSLOG
 
-            opt_syslog_enable = 1;
+            _db_set_syslog(opt_syslog_facility);
 
             break;
 
index 568cd95b1b9a68bb36a80d20b3f761a93cdbbaff..6d8552834fc9f0404194505d29a8d86828119e96 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.503 2005/01/03 16:08:26 robertc Exp $
+ * $Id: protos.h,v 1.504 2005/04/06 18:44:25 serassio Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -175,6 +175,7 @@ SQUIDCEXTERN void packerPrintf();
 SQUIDCEXTERN Ctx ctx_enter(const char *descr);
 SQUIDCEXTERN void ctx_exit(Ctx ctx);
 
+SQUIDCEXTERN void _db_set_syslog(const char *facility);
 SQUIDCEXTERN void _db_init(const char *logfile, const char *options);
 SQUIDCEXTERN void _db_rotate_log(void);