Ticket #1955: 0001-Add-a-SIGNAL-event-for-control-connections.patch

File 0001-Add-a-SIGNAL-event-for-control-connections.patch, 5.5 KB (added by special, 9 years ago)
  • doc/spec/control-spec.txt

    From 49e2018edad59c18b9b7eb4c4299e2e9d0e903b0 Mon Sep 17 00:00:00 2001
    From: John Brooks <john.brooks@dereferenced.net>
    Date: Sun, 14 Nov 2010 14:33:55 -0800
    Subject: [PATCH] Add a SIGNAL event for control connections
    
    Implements ticket #1955
    ---
     doc/spec/control-spec.txt |   19 ++++++++++++++++++-
     src/or/control.c          |   39 ++++++++++++++++++++++++++++++++++++++-
     src/or/control.h          |    1 +
     src/or/main.c             |    5 +++++
     4 files changed, 62 insertions(+), 2 deletions(-)
    
    diff --git a/doc/spec/control-spec.txt b/doc/spec/control-spec.txt
    index 2bbcfae..2b1b9d4 100644
    a b  
    228228         "INFO" / "NOTICE" / "WARN" / "ERR" / "NEWDESC" / "ADDRMAP" /
    229229         "AUTHDIR_NEWDESCS" / "DESCCHANGED" / "STATUS_GENERAL" /
    230230         "STATUS_CLIENT" / "STATUS_SERVER" / "GUARD" / "NS" / "STREAM_BW" /
    231          "CLIENTS_SEEN" / "NEWCONSENSUS" / "BUILDTIMEOUT_SET"
     231         "CLIENTS_SEEN" / "NEWCONSENSUS" / "BUILDTIMEOUT_SET" / "SIGNAL"
    232232
    233233  Any events *not* listed in the SETEVENTS line are turned off; thus, sending
    234234  SETEVENTS with an empty body turns off all event reporting.
     
    17081708
    17091709  [First added in 0.2.2.7-alpha]
    17101710
     17114.1.17. Signal received
     1712
     1713  The syntax is:
     1714     "650" SP "SIGNAL" SP Signal CRLF
     1715
     1716     Signal = "RELOAD" / "DUMP" / "DEBUG" / "NEWNYM" / "CLEARDNSCACHE"
     1717
     1718  A signal has been received and actions taken by Tor. The meaning of each
     1719  signal, and the mapping to Unix signals, is as defined in section 3.7.
     1720  If Tor chose to ignore a signal (such as NEWNYM), this event will not be
     1721  sent.
     1722
     1723  Note that the HALT (SIGTERM) and SHUTDOWN (SIGINT) signals do not currently
     1724  generate any event.
     1725
     1726  [First added in X.X.X.X-alpha]
     1727
    171117285. Implementation notes
    17121729
    171317305.1. Authentication
  • src/or/control.c

    diff --git a/src/or/control.c b/src/or/control.c
    index a2c9e46..6cb986e 100644
    a b  
    6565#define EVENT_CLIENTS_SEEN     0x0015
    6666#define EVENT_NEWCONSENSUS     0x0016
    6767#define EVENT_BUILDTIMEOUT_SET     0x0017
    68 #define _EVENT_MAX             0x0017
     68#define EVENT_SIGNAL           0x0018
     69#define _EVENT_MAX             0x0018
    6970/* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
    7071
    7172/** Bitfield: The bit 1&lt;&lt;e is set if <b>any</b> open control
    handle_control_setevents(control_connection_t *conn, uint32_t len, 
    946947        event_code = EVENT_NEWCONSENSUS;
    947948      else if (!strcasecmp(ev, "BUILDTIMEOUT_SET"))
    948949        event_code = EVENT_BUILDTIMEOUT_SET;
     950      else if (!strcasecmp(ev, "SIGNAL"))
     951        event_code = EVENT_SIGNAL;
    949952      else {
    950953        connection_printf_to_buf(conn, "552 Unrecognized event \"%s\"\r\n",
    951954                                 ev);
    control_event_buildtimeout_set(const circuit_build_times_t *cbt, 
    35893592  return 0;
    35903593}
    35913594
     3595/** Called when a signal has been processed from signal_callback */
     3596int
     3597control_event_signal(uintptr_t signal)
     3598{
     3599  const char *signal_string = NULL;
     3600
     3601  if (!control_event_is_interesting(EVENT_SIGNAL))
     3602    return 0;
     3603
     3604  switch (signal) {
     3605    case SIGHUP:
     3606      signal_string = "RELOAD";
     3607      break;
     3608    case SIGUSR1:
     3609      signal_string = "DUMP";
     3610      break;
     3611    case SIGUSR2:
     3612      signal_string = "DEBUG";
     3613      break;
     3614    case SIGNEWNYM:
     3615      signal_string = "NEWNYM";
     3616      break;
     3617    case SIGCLEARDNSCACHE:
     3618      signal_string = "CLEARDNSCACHE";
     3619      break;
     3620    default:
     3621      log_warn(LD_BUG, "Unrecognized signal %lu in control_event_signal", signal);
     3622      return -1;
     3623  }
     3624
     3625  send_control_event(EVENT_SIGNAL, ALL_FORMATS, "650 SIGNAL %s\r\n", signal_string);
     3626  return 0;
     3627}
     3628
    35923629/** Called when a single local_routerstatus_t has changed: Sends an NS event
    35933630 * to any controller that cares. */
    35943631int
  • src/or/control.h

    diff --git a/src/or/control.h b/src/or/control.h
    index 275c6de..ef91f06 100644
    a b int control_event_guard(const char *nickname, const char *digest, 
    6464                        const char *status);
    6565int control_event_buildtimeout_set(const circuit_build_times_t *cbt,
    6666                                   buildtimeout_set_event_t type);
     67int control_event_signal(uintptr_t signal);
    6768
    6869int init_cookie_authentication(int enabled);
    6970smartlist_t *decode_hashed_passwords(config_line_t *passwords);
  • src/or/main.c

    diff --git a/src/or/main.c b/src/or/main.c
    index 1e01ad1..823290a 100644
    a b signal_callback(int fd, short events, void *arg) 
    18401840    case SIGUSR1:
    18411841      /* prefer to log it at INFO, but make sure we always see it */
    18421842      dumpstats(get_min_log_level()<LOG_INFO ? get_min_log_level() : LOG_INFO);
     1843      control_event_signal(sig);
    18431844      break;
    18441845    case SIGUSR2:
    18451846      switch_logs_debug();
    18461847      log_debug(LD_GENERAL,"Caught USR2, going to loglevel debug. "
    18471848                "Send HUP to change back.");
     1849      control_event_signal(sig);
    18481850      break;
    18491851    case SIGHUP:
    18501852      if (do_hup() < 0) {
    signal_callback(int fd, short events, void *arg) 
    18521854        tor_cleanup();
    18531855        exit(1);
    18541856      }
     1857      control_event_signal(sig);
    18551858      break;
    18561859#ifdef SIGCHLD
    18571860    case SIGCHLD:
    signal_callback(int fd, short events, void *arg) 
    18681871            (int)(MAX_SIGNEWNYM_RATE+time_of_last_signewnym-now));
    18691872      } else {
    18701873        signewnym_impl(now);
     1874        control_event_signal(sig);
    18711875      }
    18721876      break;
    18731877    }
    18741878    case SIGCLEARDNSCACHE:
    18751879      addressmap_clear_transient();
     1880      control_event_signal(sig);
    18761881      break;
    18771882  }
    18781883}