summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-08-17 23:00:32 +0000
committerNick Mathewson <nickm@torproject.org>2006-08-17 23:00:32 +0000
commit0f5bfc1521afaa096df2ff66651f7f0a4f8be88a (patch)
tree6691fb9539bb685f0bde95720b209e22b2a8af7f
parentae5ee4c92436d8e7c5ac1853c42be4dd5a314f01 (diff)
downloadtor-0f5bfc1521afaa096df2ff66651f7f0a4f8be88a.tar.gz
tor-0f5bfc1521afaa096df2ff66651f7f0a4f8be88a.zip
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. svn:r7072
-rw-r--r--src/or/control.c8
-rw-r--r--src/or/main.c27
-rw-r--r--src/or/or.h3
3 files changed, 29 insertions, 9 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 1487d7dc72..ab1397cefc 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1152,15 +1152,17 @@ handle_control_signal(control_connection_t *conn, uint32_t len,
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;
}
diff --git a/src/or/main.c b/src/or/main.c
index 7493dd8320..5e27b8e441 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1196,16 +1196,33 @@ do_main_loop(void)
}
}
+/* 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 @@ control_signal_act(int the_signal)
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.
diff --git a/src/or/or.h b/src/or/or.h
index 4175b24e62..44d8c851d4 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2174,7 +2174,8 @@ void connection_start_writing(connection_t *conn);
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);