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

[or-cvs] Revise control spec and implementation to allow all log mes...



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

Modified Files:
	config.c control.c or.h 
Log Message:
Revise control spec and implementation to allow all log messages to be sent to controller with their severities intact.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.331
retrieving revision 1.332
diff -u -d -r1.331 -r1.332
--- config.c	1 Apr 2005 20:15:55 -0000	1.331
+++ config.c	5 Apr 2005 22:56:16 -0000	1.332
@@ -324,7 +324,8 @@
   /* Close the temporary log we used while starting up, if it isn't already
    * gone. */
   close_temp_logs();
-  add_callback_log(LOG_NOTICE, LOG_ERR, control_event_logmsg);
+  add_callback_log(LOG_ERR, LOG_ERR, control_event_logmsg);
+  adjust_event_log_severity();
 
   options->_ConnLimit =
     set_max_file_descriptors((unsigned)options->ConnLimit, MAXCONNECTIONS);

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- control.c	2 Apr 2005 22:11:24 -0000	1.74
+++ control.c	5 Apr 2005 22:56:16 -0000	1.75
@@ -74,9 +74,14 @@
 #define EVENT_STREAM_STATUS   0x0002
 #define EVENT_OR_CONN_STATUS  0x0003
 #define EVENT_BANDWIDTH_USED  0x0004
-#define EVENT_WARNING         0x0005
+#define EVENT_LOG_OBSOLETE    0x0005
 #define EVENT_NEW_DESC        0x0006
-#define _EVENT_MAX            0x0006
+#define EVENT_DEBUG_MSG       0x0007
+#define EVENT_INFO_MSG        0x0008
+#define EVENT_NOTICE_MSG      0x0009
+#define EVENT_WARN_MSG        0x000A
+#define EVENT_ERR_MSG         0x000B
+#define _EVENT_MAX            0x000B
 
 /** Array mapping from message type codes to human-readable message
  * type names.  */
@@ -167,13 +172,38 @@
   return (cmd<=_CONTROL_CMD_MAX_RECOGNIZED) ? CONTROL_COMMANDS[cmd] : "Unknown";
 }
 
+static INLINE int
+event_to_log_severity(int event)
+{
+  switch (event) {
+    case EVENT_DEBUG_MSG: return LOG_DEBUG;
+    case EVENT_INFO_MSG: return LOG_INFO;
+    case EVENT_NOTICE_MSG: return LOG_NOTICE;
+    case EVENT_WARN_MSG: return LOG_WARN;
+    case EVENT_ERR_MSG: return LOG_ERR;
+    default: return -1;
+  }
+}
+
+static INLINE int
+log_severity_to_event(int severity)
+{
+  switch (severity) {
+    case LOG_DEBUG: return EVENT_DEBUG_MSG;
+    case LOG_INFO: return EVENT_INFO_MSG;
+    case LOG_NOTICE: return EVENT_NOTICE_MSG;
+    case LOG_WARN: return EVENT_WARN_MSG;
+    case LOG_ERR: return EVENT_ERR_MSG;
+    default: return -1;
+  }
+}
+
 /** Set <b>global_event_mask</b> to the bitwise OR of each live control
  * connection's event_mask field. */
 static void update_global_event_mask(void)
 {
   connection_t **conns;
   int n_conns, i;
-
   global_event_mask = 0;
   get_connection_array(&conns, &n_conns);
   for (i = 0; i < n_conns; ++i) {
@@ -182,6 +212,35 @@
       global_event_mask |= conns[i]->event_mask;
     }
   }
+
+  adjust_event_log_severity();
+}
+
+void adjust_event_log_severity(void) {
+  int i;
+  int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG;
+
+  for (i = EVENT_DEBUG_MSG; i <= EVENT_ERR_MSG; ++i) {
+    if (EVENT_IS_INTERESTING(i)) {
+      min_log_event = i;
+      break;
+    }
+  }
+  for (i = EVENT_ERR_MSG; i >= EVENT_DEBUG_MSG; --i) {
+    if (EVENT_IS_INTERESTING(i)) {
+      max_log_event = i;
+      break;
+    }
+  }
+  if (EVENT_IS_INTERESTING(EVENT_LOG_OBSOLETE)) {
+    if (min_log_event > EVENT_NOTICE_MSG)
+      min_log_event = EVENT_NOTICE_MSG;
+    if (max_log_event < EVENT_ERR_MSG)
+      max_log_event = EVENT_ERR_MSG;
+  }
+  change_callback_log_severity(event_to_log_severity(min_log_event),
+                               event_to_log_severity(max_log_event),
+                               control_event_logmsg);
 }
 
 /** Send a message of type <b>type</b> containing <b>len</b> bytes
@@ -1098,14 +1157,20 @@
 void
 control_event_logmsg(int severity, const char *msg)
 {
-  size_t len;
-  if (severity > LOG_NOTICE) /* Less important than notice? ignore for now. */
-    return;
-  if (!EVENT_IS_INTERESTING(EVENT_WARNING))
-    return;
+  int oldlog = EVENT_IS_INTERESTING(EVENT_LOG_OBSOLETE) &&
+    (severity == LOG_NOTICE || severity == LOG_WARN || severity == LOG_ERR);
+  int event = log_severity_to_event(severity);
 
-  len = strlen(msg);
-  send_control_event(EVENT_WARNING, (uint32_t)(len+1), msg);
+  if (event<0 || !EVENT_IS_INTERESTING(event))
+    event = 0;
+
+  if (oldlog || event) {
+    size_t len = strlen(msg);
+    if (event)
+      send_control_event(event, (uint32_t)(len+1), msg);
+    if (oldlog)
+      send_control_event(EVENT_LOG_OBSOLETE, (uint32_t)(len+1), msg);
+  }
 }
 
 /** Called whenever we receive new router descriptors: tell any

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.583
retrieving revision 1.584
diff -u -d -r1.583 -r1.584
--- or.h	3 Apr 2005 05:22:33 -0000	1.583
+++ or.h	5 Apr 2005 22:56:16 -0000	1.584
@@ -1407,6 +1407,7 @@
   OR_CONN_EVENT_CLOSED       = 3,
 } or_conn_status_event_t;
 
+void adjust_event_log_severity(void);
 int connection_control_finished_flushing(connection_t *conn);
 int connection_control_reached_eof(connection_t *conn);
 int connection_control_process_inbuf(connection_t *conn);