[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Add SysLog option to direct log messages to the system log ...



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv9964/src/or

Modified Files:
	config.c 
Log Message:
Add SysLog option to direct log messages to the system log instead of a FILE*.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.185
retrieving revision 1.186
diff -u -d -r1.185 -r1.186
--- config.c	25 Oct 2004 06:16:26 -0000	1.185
+++ config.c	26 Oct 2004 21:48:41 -0000	1.186
@@ -292,7 +292,7 @@
       config_compare(list, "SocksPort",      CONFIG_TYPE_UINT, &options->SocksPort) ||
       config_compare(list, "SocksBindAddress",CONFIG_TYPE_LINELIST,&options->SocksBindAddress) ||
       config_compare(list, "SocksPolicy",     CONFIG_TYPE_LINELIST,&options->SocksPolicy) ||
-
+      config_compare(list, "SysLog",          CONFIG_TYPE_LINELIST,&options->LogOptions) ||
       config_compare(list, "TrafficShaping", CONFIG_TYPE_OBSOLETE, NULL) ||
 
       config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User)
@@ -964,7 +964,8 @@
   } else {
     levelMax = LOG_ERR;
   }
-  if (file_opt) {
+
+  if (file_opt && !strcasecmp(file_opt->key, "LogFile")) {
     if (add_file_log(levelMin, levelMax, file_opt->value) < 0) {
       log_fn(LOG_WARN, "Cannot write to LogFile '%s': %s.", file_opt->value,
              strerror(errno));
@@ -972,6 +973,16 @@
     }
     log_fn(LOG_NOTICE, "Successfully opened LogFile '%s', redirecting output.",
            file_opt->value);
+  } else if (file_opt && !strcasecmp(file_opt->key, "SysLog")) {
+#ifdef HAVE_SYSLOG_H
+    if (add_syslog_log(levelMin, levelMax) < 0) {
+      log_fn(LOG_WARN, "Cannot open system log facility");
+      return -1;
+    }
+    log_fn(LOG_NOTICE, "Successfully opened system log, redirecting output.");
+#else
+    log_fn(LOG_WARN, "Tor was compiled without system logging enabled; can't enable SysLog.");
+#endif
   } else if (!isDaemon) {
     add_stream_log(levelMin, levelMax, "<stdout>", stdout);
     close_temp_logs();
@@ -998,7 +1009,8 @@
 
   /* Special case for if first option is LogLevel. */
   if (opt && !strcasecmp(opt->key, "LogLevel")) {
-    if (opt->next && !strcasecmp(opt->next->key, "LogFile")) {
+    if (opt->next && (!strcasecmp(opt->next->key, "LogFile") ||
+                      !strcasecmp(opt->next->key, "SysLog"))) {
       if (add_single_log(opt, opt->next, options->RunAsDaemon) < 0)
         return -1;
       opt = opt->next->next;
@@ -1013,17 +1025,18 @@
 
   while (opt) {
     if (!strcasecmp(opt->key, "LogLevel")) {
-      log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile");
+      log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile or SysLog");
       opt = opt->next;
     } else {
-      tor_assert(!strcasecmp(opt->key, "LogFile"));
+      tor_assert(!strcasecmp(opt->key, "LogFile") ||
+                 !strcasecmp(opt->key, "SysLog"));
       if (opt->next && !strcasecmp(opt->next->key, "LogLevel")) {
-        /* LogFile followed by LogLevel */
+        /* LogFile/SysLog followed by LogLevel */
         if (add_single_log(opt->next, opt, options->RunAsDaemon) < 0)
           return -1;
         opt = opt->next->next;
       } else {
-        /* LogFile followed by LogFile or end of list. */
+        /* LogFile/SysLog followed by LogFile/SysLog or end of list. */
         if (add_single_log(NULL, opt, options->RunAsDaemon) < 0)
           return -1;
         opt = opt->next;