[or-cvs] r13888: Change semantics of add-a-log functions to copy severity set (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Sat Mar 8 01:11:54 UTC 2008


Author: nickm
Date: 2008-03-07 20:11:54 -0500 (Fri, 07 Mar 2008)
New Revision: 13888

Modified:
   tor/trunk/
   tor/trunk/src/common/log.c
   tor/trunk/src/or/config.c
Log:
 r18639 at catbus:  nickm | 2008-03-07 20:11:48 -0500
 Change semantics of add-a-log functions to copy severity setup: that is way less error-prone.  Fix up config.c to act accordingly.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r18639] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/common/log.c
===================================================================
--- tor/trunk/src/common/log.c	2008-03-08 01:11:52 UTC (rev 13887)
+++ tor/trunk/src/common/log.c	2008-03-08 01:11:54 UTC (rev 13888)
@@ -480,8 +480,7 @@
 }
 
 /** Add a log handler named <b>name</b> to send all messages in <b>severity</b>
- * to <b>stream</b>. Steals a reference to <b>severity</b>; the caller must
- * not use it after calling this function. Helper: does no locking. */
+ * to <b>stream</b>. Copies <b>severity</b>. Helper: does no locking. */
 static void
 add_stream_log_impl(log_severity_list_t *severity,
                     const char *name, FILE *stream)
@@ -489,7 +488,7 @@
   logfile_t *lf;
   lf = tor_malloc_zero(sizeof(logfile_t));
   lf->filename = tor_strdup(name);
-  lf->severities = severity;
+  lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
   lf->file = stream;
   lf->next = logfiles;
 
@@ -539,7 +538,7 @@
 {
   logfile_t *lf;
   lf = tor_malloc_zero(sizeof(logfile_t));
-  lf->severities = severity;
+  lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
   lf->filename = tor_strdup("<callback>");
   lf->callback = cb;
   lf->next = logfiles;
@@ -657,7 +656,7 @@
     openlog("Tor", LOG_PID | LOG_NDELAY, LOGFACILITY);
 
   lf = tor_malloc_zero(sizeof(logfile_t));
-  lf->severities = severity;
+  lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
   lf->filename = tor_strdup("<syslog>");
 
   lf->is_syslog = 1;

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-03-08 01:11:52 UTC (rev 13887)
+++ tor/trunk/src/or/config.c	2008-03-08 01:11:54 UTC (rev 13888)
@@ -1055,6 +1055,7 @@
     close_temp_logs();
     add_callback_log(severity, control_event_logmsg);
     control_adjust_event_log_severity();
+    tor_free(severity);
   }
   SMARTLIST_FOREACH(replaced_listeners, connection_t *, conn,
   {
@@ -3770,7 +3771,6 @@
         } else {
           add_stream_log(severity, err?"<stderr>":"<stdout>",
                          err?stderr:stdout);
-          severity=NULL;
         }
       }
       goto cleanup;
@@ -3780,7 +3780,6 @@
 #ifdef HAVE_SYSLOG_H
       if (!validate_only) {
         add_syslog_log(severity);
-        severity=NULL;
       }
 #else
       log_warn(LD_CONFIG, "Syslog is not supported on this system. Sorry.");
@@ -3794,8 +3793,6 @@
         if (add_file_log(severity, smartlist_get(elts, 1)) < 0) {
           log_warn(LD_CONFIG, "Couldn't open file for 'Log %s'", opt->value);
           ok = 0;
-        } else {
-          tor_free(severity);
         }
       }
       goto cleanup;



More information about the tor-commits mailing list