Improve documentation for signal code

This commit is contained in:
Nick Mathewson 2018-01-19 10:02:20 -05:00
parent 20f802ea3c
commit 65a27d95e7

View File

@ -3016,9 +3016,15 @@ exit_function(void)
#else #else
#define UNIX_ONLY 1 #define UNIX_ONLY 1
#endif #endif
static struct { static struct {
/** A numeric code for this signal. Must match the signal value if
* try_to_register is true. */
int signal_value; int signal_value;
/** True if we should try to register this signal with libevent and catch
* corresponding posix signals. False otherwise. */
int try_to_register; int try_to_register;
/** Pointer to hold the event object constructed for this signal. */
struct event *signal_event; struct event *signal_event;
} signal_handlers[] = { } signal_handlers[] = {
#ifdef SIGINT #ifdef SIGINT
@ -3052,7 +3058,8 @@ static struct {
{ -1, -1, NULL } { -1, -1, NULL }
}; };
/** Set up the signal handlers for this process. */ /** Set up the signal handler events for this process, and register them
* with libevent if appropriate. */
void void
handle_signals(void) handle_signals(void)
{ {
@ -3060,6 +3067,11 @@ handle_signals(void)
const int enabled = !get_options()->DisableSignalHandlers; const int enabled = !get_options()->DisableSignalHandlers;
for (i = 0; signal_handlers[i].signal_value >= 0; ++i) { for (i = 0; signal_handlers[i].signal_value >= 0; ++i) {
/* Signal handlers are only registered with libevent if they need to catch
* real POSIX signals. We construct these signal handler events in either
* case, though, so that controllers can activate them with the SIGNAL
* command.
*/
if (enabled && signal_handlers[i].try_to_register) { if (enabled && signal_handlers[i].try_to_register) {
signal_handlers[i].signal_event = signal_handlers[i].signal_event =
tor_evsignal_new(tor_libevent_get_base(), tor_evsignal_new(tor_libevent_get_base(),
@ -3079,7 +3091,7 @@ handle_signals(void)
} }
} }
/* Make sure the signal handler for signal_num will be called. */ /* Cause the signal handler for signal_num to be called in the event loop. */
void void
activate_signal(int signal_num) activate_signal(int signal_num)
{ {