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

[or-cvs] Implement SIGNAL control command.



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

Modified Files:
	control.c main.c or.h 
Log Message:
Implement SIGNAL control command.

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- control.c	21 Dec 2004 02:57:25 -0000	1.39
+++ control.c	5 Jan 2005 06:40:47 -0000	1.40
@@ -39,7 +39,8 @@
 #define CONTROL_CMD_EVENT        0x0006
 #define CONTROL_CMD_AUTHENTICATE 0x0007
 #define CONTROL_CMD_SAVECONF     0x0008
-#define _CONTROL_CMD_MAX_RECOGNIZED 0x0008
+#define CONTROL_CMD_SIGNAL       0x0009
+#define _CONTROL_CMD_MAX_RECOGNIZED 0x0009
 
 /* Recognized error codes. */
 #define ERR_UNSPECIFIED             0x0000
@@ -113,6 +114,8 @@
                                        const char *body);
 static int handle_control_saveconf(connection_t *conn, uint16_t len,
                                    const char *body);
+static int handle_control_signal(connection_t *conn, uint16_t len,
+                                 const char *body);
 
 /** Given a possibly invalid message type code <b>cmd</b>, return a
  * human-readable string equivalent. */
@@ -398,6 +401,21 @@
   return 0;
 }
 
+static int
+handle_control_signal(connection_t *conn, uint16_t len,
+                      const char *body)
+{
+  if (len != 1) {
+    send_control_error(conn, ERR_SYNTAX,
+                       "Body of SIGNAL command too long or two short.");
+  } else if (control_signal_act((uint8_t)body[0]) < 0) {
+    send_control_error(conn, ERR_SYNTAX, "Unrecognized signal number.");
+  } else {
+    send_control_done(conn);
+  }
+  return 0;
+}
+
 /** Called when <b>conn</b> has no more bytes left on its outbuf. */
 int
 connection_control_finished_flushing(connection_t *conn) {
@@ -477,6 +495,10 @@
       if (handle_control_saveconf(conn, body_len, body))
         return -1;
       break;
+    case CONTROL_CMD_SIGNAL:
+      if (handle_control_signal(conn, body_len, body))
+        return -1;
+      break;
     case CONTROL_CMD_ERROR:
     case CONTROL_CMD_DONE:
     case CONTROL_CMD_CONFVALUE:

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.412
retrieving revision 1.413
diff -u -d -r1.412 -r1.413
--- main.c	3 Jan 2005 20:51:24 -0000	1.412
+++ main.c	5 Jan 2005 06:40:47 -0000	1.413
@@ -922,6 +922,41 @@
   }
 }
 
+/** 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. */
+/* 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
+control_signal_act(int the_signal)
+{
+  switch(the_signal)
+    {
+    case 1:
+      please_reset = 1;
+      break;
+    case 2:
+      please_shutdown = 1;
+      break;
+    case 10:
+      please_dumpstats = 1;
+      break;
+    case 12:
+      please_debug = 1;
+      break;
+    case 15:
+      please_die = 1;
+      break;
+    default:
+      return -1;
+    }
+  return 0;
+}
+
 /** Unix signal handler. */
 static void catch(int the_signal) {
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.517
retrieving revision 1.518
diff -u -d -r1.517 -r1.518
--- or.h	5 Jan 2005 06:05:37 -0000	1.517
+++ or.h	5 Jan 2005 06:40:47 -0000	1.518
@@ -1387,6 +1387,7 @@
 int advertised_server_mode(void);
 int proxy_mode(or_options_t *options);
 
+int control_signal_act(int the_signal);
 void handle_signals(int is_parent);
 void tor_cleanup(void);