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

[or-cvs] r7072: patch suggested by Karsten Loesing: respond to SIGNAL comman (in tor/trunk: . src/or)



Author: nickm
Date: 2006-08-17 19:00:32 -0400 (Thu, 17 Aug 2006)
New Revision: 7072

Modified:
   tor/trunk/
   tor/trunk/src/or/control.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
Log:
 r7411@Kushana:  nickm | 2006-08-17 19:00:25 -0400
 patch suggested by Karsten Loesing: respond to SIGNAL command before we execute the signal, in case the signal shuts us down.



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - 17f730b7-d419-0410-b50f-85ee4b70197a:/local/or/tor/trunk:8290
1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
96637b51-b116-0410-a10e-9941ebb49b64:/tor/branches/spec:7005
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7405
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7030
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/trans-ap:7315
c95137ef-5f19-0410-b913-86e773d04f59:/tor/trunk:7393
   + 17f730b7-d419-0410-b50f-85ee4b70197a:/local/or/tor/trunk:8290
1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
96637b51-b116-0410-a10e-9941ebb49b64:/tor/branches/spec:7005
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7405
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7030
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/trans-ap:7315
c95137ef-5f19-0410-b913-86e773d04f59:/tor/trunk:7411

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2006-08-17 22:49:29 UTC (rev 7071)
+++ tor/trunk/src/or/control.c	2006-08-17 23:00:32 UTC (rev 7072)
@@ -1152,15 +1152,17 @@
     if (sig<0)
       return 0;
   }
-
-  if (control_signal_act(sig) < 0) {
+  
+  if (!control_signal_check(sig)) {
     if (STATE_IS_V0(conn->_base.state))
       send_control0_error(conn, ERR_SYNTAX, "Unrecognized signal number.");
     else
-      connection_write_str_to_buf("551 Internal error acting on signal\r\n",
+      connection_write_str_to_buf("551 Unable to act on signal\r\n",
                                   conn);
   } else {
+    /* Send DONE first, in case the signal makes us shut down. */
     send_control_done(conn);
+    control_signal_act(sig);
   }
   return 0;
 }

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2006-08-17 22:49:29 UTC (rev 7071)
+++ tor/trunk/src/or/main.c	2006-08-17 23:00:32 UTC (rev 7072)
@@ -1196,16 +1196,33 @@
   }
 }
 
+/* DOCDOC */
+int
+control_signal_check(int the_signal)
+{
+  switch (the_signal)
+    {
+    case 1:
+    case 2:
+    case 10:
+    case 12:
+    case 15:
+    case SIGNEWNYM:
+      return 1;
+    default:
+      return 0;
+    }
+}
+
 /** Used to implement the SIGNAL control command: if we accept
- * <b>the_signal</b> as a remote pseudo-signal, then act on it and
- * return 0.  Else return -1. */
+ * <b>the_signal</b> as a remote pseudo-signal, act on it. */
 /* We don't re-use catch() here because:
  *   1. We handle a different set of signals than those allowed in catch.
  *   2. Platforms without signal() are unlikely to define SIGfoo.
  *   3. The control spec is defined to use fixed numeric signal values
  *      which just happen to match the unix values.
  */
-int
+void
 control_signal_act(int the_signal)
 {
   switch (the_signal)
@@ -1229,9 +1246,9 @@
       signal_callback(0,0,(void*)(uintptr_t)SIGNEWNYM);
       break;
     default:
-      return -1;
+      log_warn(LD_BUG, "Unrecognized signal number %d.", the_signal);
+      break;
     }
-  return 0;
 }
 
 /** Libevent callback: invoked when we get a signal.

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2006-08-17 22:49:29 UTC (rev 7071)
+++ tor/trunk/src/or/or.h	2006-08-17 23:00:32 UTC (rev 7072)
@@ -2174,7 +2174,8 @@
 void directory_all_unreachable(time_t now);
 void directory_info_has_arrived(time_t now, int from_cache);
 
-int control_signal_act(int the_signal);
+int control_signal_check(int the_signal);
+void control_signal_act(int the_signal);
 void handle_signals(int is_parent);
 void tor_cleanup(void);
 void tor_free_all(int postfork);