[or-cvs] Tinker with log behavior: never send error messages about l...

Nick Mathewson nickm at seul.org
Thu May 20 19:47:31 UTC 2004


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

Modified Files:
	log.c log.h 
Log Message:
Tinker with log behavior: never send error messages about logs into the bitbucket

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- log.c	19 May 2004 20:07:07 -0000	1.41
+++ log.c	20 May 2004 19:47:28 -0000	1.42
@@ -25,11 +25,12 @@
 /** Information for a single logfile; only used in log.c */
 typedef struct logfile_t {
   struct logfile_t *next; /**< Next logfile_t in the linked list. */
-  const char *filename; /**< Filename to open. */
+  char *filename; /**< Filename to open. */
   FILE *file; /**< Stream to receive log messages. */
   int needs_close; /**< Boolean: true if the stream gets closed on shutdown. */
   int loglevel; /**< Lowest severity level to send to this stream. */
   int max_loglevel; /**< Highest severity level to send to this stream. */
+  int is_temporary; /**< Boolean: close after initializing logging subsystem.*/
 } logfile_t;
 
 /** Helper: map a log severity to descriptive string. */
@@ -145,7 +146,8 @@
     logfiles = logfiles->next;
     if (victim->needs_close)
       fclose(victim->file);
-    free(victim);
+    tor_free(victim->filename);
+    tor_free(victim);
   }
 }
 
@@ -167,15 +169,42 @@
 {
   logfile_t *lf;
   lf = tor_malloc(sizeof(logfile_t));
-  lf->filename = name;
+  lf->filename = tor_strdup(name);
   lf->needs_close = 0;
   lf->loglevel = loglevelMin;
   lf->max_loglevel = loglevelMax;
   lf->file = stream;
   lf->next = logfiles;
+  lf->is_temporary = 0;
   logfiles = lf;
 }
 
+/** Add a log handler to receive messages during startup (before the real
+ * logs are initialized).
+ */
+void add_temp_log(void)
+{
+  add_stream_log(LOG_INFO, LOG_ERR, "<temp>", stdout);
+  logfiles->is_temporary = 1;
+}
+
+void close_temp_logs(void)
+{
+  logfile_t *lf, **p;
+  for (p = &logfiles; *p; ) {
+    if ((*p)->is_temporary) {
+      lf = *p;
+      *p = (*p)->next;
+      if (lf->needs_close)
+        fclose(lf->file);
+      tor_free(lf->filename);
+      tor_free(lf);
+    } else {
+      p = &((*p)->next);
+    }
+  }
+}
+
 /**
  * Add a log handler to send messages to <b>filename</b>. If opening
  * the logfile fails, -1 is returned and errno is set appropriately

Index: log.h
===================================================================
RCS file: /home/or/cvsroot/src/common/log.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- log.h	19 May 2004 20:07:07 -0000	1.25
+++ log.h	20 May 2004 19:47:28 -0000	1.26
@@ -52,6 +52,8 @@
 int get_min_log_level(void);
 void close_logs();
 void reset_logs();
+void add_temp_log(void);
+void close_temp_logs(void);
 
 /* Outputs a message to stdout */
 void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);



More information about the tor-commits mailing list