[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/maint-0.4.2] Rewrite control_event_signal() to use signal_table.
commit 7bd671811ec38e8126ffc17cb922f2397c572cda
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Jan 30 09:29:07 2020 -0500
Rewrite control_event_signal() to use signal_table.
When we added the ACTIVE and DORMANT virtual signals, we taught the
signal command to handle them, but we didn't teach SIGNAL event to
report them.
To solve this problem and prevent it from recurring, this patch
revises the implementation of control_event_signal() to use the same
signal_table that handle_control_signal() uses. This way, the two
controller commands can't become out of sync.
Fixes bug 33104; bugfix on 0.4.0.1-alpha.
---
changes/bug33104 | 4 ++++
src/feature/control/control.c | 4 ++++
src/feature/control/control_events.c | 32 ++++++++++----------------------
3 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/changes/bug33104 b/changes/bug33104
new file mode 100644
index 000000000..b5478df10
--- /dev/null
+++ b/changes/bug33104
@@ -0,0 +1,4 @@
+ o Minor bugfixes (controller):
+ - When receiving "ACTIVE" or "DORMANT" signals on the control port,
+ report them as SIGNAL events. Fixes bug 33104; bugfix on
+ 0.4.0.1-alpha.
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index 436bf423c..71b864751 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -158,6 +158,10 @@ control_ports_write_to_file(void)
}
const struct signal_name_t signal_table[] = {
+ /* NOTE: this table is used for handling SIGNAL commands and generating
+ * SIGNAL events. Order is significant: if there are two entries for the
+ * same numeric signal, the first one is the canonical name generated
+ * for the events. */
{ SIGHUP, "RELOAD" },
{ SIGHUP, "HUP" },
{ SIGINT, "SHUTDOWN" },
diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c
index 9e0966ca5..1089b608b 100644
--- a/src/feature/control/control_events.c
+++ b/src/feature/control/control_events.c
@@ -1552,29 +1552,17 @@ control_event_signal(uintptr_t signal_num)
if (!control_event_is_interesting(EVENT_GOT_SIGNAL))
return 0;
- switch (signal_num) {
- case SIGHUP:
- signal_string = "RELOAD";
+ for (unsigned i = 0; signal_table[i].signal_name != NULL; ++i) {
+ if ((int)signal_num == signal_table[i].sig) {
+ signal_string = signal_table[i].signal_name;
break;
- case SIGUSR1:
- signal_string = "DUMP";
- break;
- case SIGUSR2:
- signal_string = "DEBUG";
- break;
- case SIGNEWNYM:
- signal_string = "NEWNYM";
- break;
- case SIGCLEARDNSCACHE:
- signal_string = "CLEARDNSCACHE";
- break;
- case SIGHEARTBEAT:
- signal_string = "HEARTBEAT";
- break;
- default:
- log_warn(LD_BUG, "Unrecognized signal %lu in control_event_signal",
- (unsigned long)signal_num);
- return -1;
+ }
+ }
+
+ if (signal_string == NULL) {
+ log_warn(LD_BUG, "Unrecognized signal %lu in control_event_signal",
+ (unsigned long)signal_num);
+ return -1;
}
send_control_event(EVENT_GOT_SIGNAL, "650 SIGNAL %s\r\n",
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits