浏览代码

options_init_from_torrc(): Split argv processing into two parts

Split the argv processing loop into two poarts, one that deals with
figuring out which conffile to use, and the other that figures out
which "command" (hash fingerprint, verify config, list fpr, run tor)
the user asked for.

There is a third part further down that imports command line args
into the config but that is not touched.


svn:r13941
Peter Palfrader 17 年之前
父节点
当前提交
4118e319c7
共有 1 个文件被更改,包括 13 次插入9 次删除
  1. 13 9
      src/or/config.c

+ 13 - 9
src/or/config.c

@@ -3569,12 +3569,24 @@ options_init_from_torrc(int argc, char **argv)
   newoptions = tor_malloc_zero(sizeof(or_options_t));
   newoptions->_magic = OR_OPTIONS_MAGIC;
   options_init(newoptions);
+  newoptions->command = CMD_RUN_TOR;
+
+  for (i = 1; i < argc; ++i) {
+    if (!strcmp(argv[i],"--list-fingerprint")) {
+      newoptions->command = CMD_LIST_FINGERPRINT;
+    } else if (!strcmp(argv[i],"--hash-password")) {
+      newoptions->command = CMD_HASH_PASSWORD;
+      newoptions->command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : "");
+      ++i;
+    } else if (!strcmp(argv[i],"--verify-config")) {
+      newoptions->command = CMD_VERIFY_CONFIG;
+    }
+  }
 
   /* learn config file name */
   fname = NULL;
   using_default_torrc = 1;
   ignore_missing_torrc = 0;
-  newoptions->command = CMD_RUN_TOR;
   for (i = 1; i < argc; ++i) {
     if (i < argc-1 && !strcmp(argv[i],"-f")) {
       if (fname) {
@@ -3592,14 +3604,6 @@ options_init_from_torrc(int argc, char **argv)
       ++i;
     } else if (!strcmp(argv[i],"--ignore-missing-torrc")) {
       ignore_missing_torrc = 1;
-    } else if (!strcmp(argv[i],"--list-fingerprint")) {
-      newoptions->command = CMD_LIST_FINGERPRINT;
-    } else if (!strcmp(argv[i],"--hash-password")) {
-      newoptions->command = CMD_HASH_PASSWORD;
-      newoptions->command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : "");
-      ++i;
-    } else if (!strcmp(argv[i],"--verify-config")) {
-      newoptions->command = CMD_VERIFY_CONFIG;
     }
   }
   if (using_default_torrc) {