[tor-commits] [tor/master] Rationalize handling of quiet_level in config.c

nickm at torproject.org nickm at torproject.org
Tue Oct 22 11:50:50 UTC 2019


commit e07b19d3055f9ce080efaf2295f1ca096b10db3c
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Oct 17 13:13:52 2019 -0400

    Rationalize handling of quiet_level in config.c
    
    Formerly, we would use quiet_level as an excuse to rewrite the log
    configuration, adding a default log line if none existed, and if
    RunAsDaemon was not set, and if we were not being invoked via
    setconf (!).
    
    This is against our best practices for several reasons:
      * We should not be changing configured options except when the
        user tells us to do so.
      * We should especially not be changing options in the options_validate
        function.
      * Distinguishing whether we are being called from setconf adds a
        risky special-case.
    
    Instead, this patch take a simpler approach: it changes the
    interpretation of having no logging lines set to mean: If there is a
    stdout, add a default log based on quiet_level.
    
    Solves ticket 31999.
---
 src/app/config/config.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 37eab2291..0a8c0d536 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -3428,20 +3428,17 @@ options_validate_single_onion(or_options_t *options, char **msg)
  * normalizing the contents of <b>options</b>.
  *
  * On error, tor_strdup an error explanation into *<b>msg</b>.
- *
- * XXX
- * If <b>from_setconf</b>, we were called by the controller, and our
- * Log line should stay empty. If it's 0, then give us a default log
- * if there are no logs defined.
  */
 STATIC int
 options_validate(or_options_t *old_options, or_options_t *options,
-                 or_options_t *default_options, int from_setconf, char **msg)
+                 or_options_t *default_options, int from_setconf_unused,
+                 char **msg)
 {
   config_line_t *cl;
   const char *uname = get_uname();
   int n_ports=0;
   int world_writable_control_socket=0;
+  (void)from_setconf_unused; /* 29211 TODO: Remove this from the API. */
 
   tor_assert(msg);
   *msg = NULL;
@@ -3504,14 +3501,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
 
   check_network_configuration(server_mode(options));
 
-  /* Special case on first boot if no Log options are given. */
-  if (!options->Logs && !options->RunAsDaemon && !from_setconf) {
-    if (quiet_level == 0)
-      config_line_append(&options->Logs, "Log", "notice stdout");
-    else if (quiet_level == 1)
-      config_line_append(&options->Logs, "Log", "warn stdout");
-  }
-
   /* Validate the tor_log(s) */
   if (options_init_logs(old_options, options, 1)<0)
     REJECT("Failed to validate Log options. See logs for details.");
@@ -5733,6 +5722,12 @@ options_init_logs(const or_options_t *old_options, or_options_t *options,
   ok = 1;
   elts = smartlist_new();
 
+  if (options->Logs == NULL && !run_as_daemon && !validate_only) {
+    /* When no logs are given, the default behavior is to log nothing (if
+       RunAsDaemon is set) or to log based on the quiet level otherwise. */
+    add_default_log_for_quiet_level(quiet_level);
+  }
+
   for (opt = options->Logs; opt; opt = opt->next) {
     log_severity_list_t *severity;
     const char *cfg = opt->value;





More information about the tor-commits mailing list