Browse Source

New controller command "getinfo config-text"

It returns the contents that Tor would write if you send it a SAVECONF
command, so the controller can write the file to disk itself.
Roger Dingledine 15 years ago
parent
commit
f7d99b62a3
6 changed files with 17 additions and 4 deletions
  1. 3 0
      ChangeLog
  2. 7 0
      doc/spec/control-spec.txt
  3. 1 1
      src/or/config.c
  4. 4 2
      src/or/control.c
  5. 1 1
      src/or/networkstatus.c
  6. 1 0
      src/or/or.h

+ 3 - 0
ChangeLog

@@ -4,6 +4,9 @@ Changes in version 0.2.2.7-alpha - 2009-??-??
       timeout schedule for how many seconds until we detach a stream from
       timeout schedule for how many seconds until we detach a stream from
       a circuit and try a new circuit. If your network is particularly
       a circuit and try a new circuit. If your network is particularly
       slow, you might want to set this to a number like 60.
       slow, you might want to set this to a number like 60.
+    - New controller command "getinfo config-text". It returns the
+      contents that Tor would write if you send it a SAVECONF command,
+      so the controller can write the file to disk itself.
 
 
   o Minor bugfixes:
   o Minor bugfixes:
     - Fix compilation on OSX 10.3, which has a stub mlockall() but
     - Fix compilation on OSX 10.3, which has a stub mlockall() but

+ 7 - 0
doc/spec/control-spec.txt

@@ -270,6 +270,9 @@
   returns "250 OK" if successful, or "551 Unable to write configuration
   returns "250 OK" if successful, or "551 Unable to write configuration
   to disk" if it can't write the file or some other error occurs.
   to disk" if it can't write the file or some other error occurs.
 
 
+  See also the "getinfo config-text" command, if the controller wants
+  to write the torrc file itself.
+
 3.7. SIGNAL
 3.7. SIGNAL
 
 
   Sent from the client to the server. The syntax is:
   Sent from the client to the server. The syntax is:
@@ -378,6 +381,10 @@
 
 
     "config-file" -- The location of Tor's configuration file ("torrc").
     "config-file" -- The location of Tor's configuration file ("torrc").
 
 
+    "config-text" -- The contents that Tor would write if you send it
+      a SAVECONF command, so the controller can write the file to
+      disk itself. [First implemented in 0.2.2.7-alpha.]
+
     ["exit-policy/prepend" -- The default exit policy lines that Tor will
     ["exit-policy/prepend" -- The default exit policy lines that Tor will
       *prepend* to the ExitPolicy config option.
       *prepend* to the ExitPolicy config option.
      -- Never implemented. Useful?]
      -- Never implemented. Useful?]

+ 1 - 1
src/or/config.c

@@ -2843,7 +2843,7 @@ config_dump(config_format_t *fmt, void *options, int minimal,
  * the configuration in <b>options</b>.  If <b>minimal</b> is true, do not
  * the configuration in <b>options</b>.  If <b>minimal</b> is true, do not
  * include options that are the same as Tor's defaults.
  * include options that are the same as Tor's defaults.
  */
  */
-static char *
+char *
 options_dump(or_options_t *options, int minimal)
 options_dump(or_options_t *options, int minimal)
 {
 {
   return config_dump(&options_format, options, minimal, 0);
   return config_dump(&options_format, options, minimal, 0);

+ 4 - 2
src/or/control.c

@@ -114,8 +114,6 @@ static int handle_control_setevents(control_connection_t *conn, uint32_t len,
 static int handle_control_authenticate(control_connection_t *conn,
 static int handle_control_authenticate(control_connection_t *conn,
                                        uint32_t len,
                                        uint32_t len,
                                        const char *body);
                                        const char *body);
-static int handle_control_saveconf(control_connection_t *conn, uint32_t len,
-                                   const char *body);
 static int handle_control_signal(control_connection_t *conn, uint32_t len,
 static int handle_control_signal(control_connection_t *conn, uint32_t len,
                                  const char *body);
                                  const char *body);
 static int handle_control_mapaddress(control_connection_t *conn, uint32_t len,
 static int handle_control_mapaddress(control_connection_t *conn, uint32_t len,
@@ -1301,6 +1299,8 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
     *answer = tor_strdup(get_version());
     *answer = tor_strdup(get_version());
   } else if (!strcmp(question, "config-file")) {
   } else if (!strcmp(question, "config-file")) {
     *answer = tor_strdup(get_torrc_fname());
     *answer = tor_strdup(get_torrc_fname());
+  } else if (!strcmp(question, "config-text")) {
+    *answer = options_dump(get_options(), 1);
   } else if (!strcmp(question, "info/names")) {
   } else if (!strcmp(question, "info/names")) {
     *answer = list_getinfo_options();
     *answer = list_getinfo_options();
   } else if (!strcmp(question, "events/names")) {
   } else if (!strcmp(question, "events/names")) {
@@ -1802,6 +1802,8 @@ typedef struct getinfo_item_t {
 static const getinfo_item_t getinfo_items[] = {
 static const getinfo_item_t getinfo_items[] = {
   ITEM("version", misc, "The current version of Tor."),
   ITEM("version", misc, "The current version of Tor."),
   ITEM("config-file", misc, "Current location of the \"torrc\" file."),
   ITEM("config-file", misc, "Current location of the \"torrc\" file."),
+  ITEM("config-text", misc,
+       "Return the string that would be written by a saveconf command."),
   ITEM("accounting/bytes", accounting,
   ITEM("accounting/bytes", accounting,
        "Number of bytes read/written so far in the accounting interval."),
        "Number of bytes read/written so far in the accounting interval."),
   ITEM("accounting/bytes-left", accounting,
   ITEM("accounting/bytes-left", accounting,

+ 1 - 1
src/or/networkstatus.c

@@ -2084,7 +2084,7 @@ networkstatus_get_flavor_name(consensus_flavor_t flav)
 }
 }
 
 
 /** Return the consensus_flavor_t value for the flavor called <b>flavname</b>,
 /** Return the consensus_flavor_t value for the flavor called <b>flavname</b>,
- * or -1 if the flavor is not recongized. */
+ * or -1 if the flavor is not recognized. */
 int
 int
 networkstatus_parse_flavor_name(const char *flavname)
 networkstatus_parse_flavor_name(const char *flavname)
 {
 {

+ 1 - 0
src/or/or.h

@@ -3219,6 +3219,7 @@ int resolve_my_address(int warn_severity, or_options_t *options,
                        uint32_t *addr, char **hostname_out);
                        uint32_t *addr, char **hostname_out);
 int is_local_addr(const tor_addr_t *addr) ATTR_PURE;
 int is_local_addr(const tor_addr_t *addr) ATTR_PURE;
 void options_init(or_options_t *options);
 void options_init(or_options_t *options);
+char *options_dump(or_options_t *options, int minimal);
 int options_init_from_torrc(int argc, char **argv);
 int options_init_from_torrc(int argc, char **argv);
 setopt_err_t options_init_from_string(const char *cf,
 setopt_err_t options_init_from_string(const char *cf,
                             int command, const char *command_arg, char **msg);
                             int command, const char *command_arg, char **msg);