From: Nick Mathewson Date: Fri, 13 Sep 2013 16:55:53 +0000 (-0400) Subject: Merge remote-tracking branch 'Ryman/bug6384' X-Git-Tag: tor-0.2.5.1-alpha~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25a3ae922f2f378c16c5930b76c33917480120d8;p=thirdparty%2Ftor.git Merge remote-tracking branch 'Ryman/bug6384' Conflicts: src/or/config.c src/or/main.c --- 25a3ae922f2f378c16c5930b76c33917480120d8 diff --cc src/or/config.c index 9a8d1e77f5,b00f0d6e11..5ce7bad493 --- a/src/or/config.c +++ b/src/or/config.c @@@ -1794,48 -1791,15 +1795,49 @@@ options_act(const or_options_t *old_opt return 0; } -/** Helper: Read a list of configuration options from the command line. - * If successful, put them in *result and return 0, and return - * -1 and leave *result alone. */ -static int -config_get_commandlines(int argc, char **argv, config_line_t **result) +static const struct { + const char *name; + int takes_argument; +} CMDLINE_ONLY_OPTIONS[] = { + { "-f", 1 }, + { "--defaults-torrc", 1 }, + { "--hash-password", 1 }, + { "--dump-config", 1 }, + { "--list-fingerprint", 0 }, + { "--verify-config", 0 }, + { "--ignore-missing-torrc", 0 }, + { "--quiet", 0 }, + { "--hush", 0 }, + { "--version", 0 }, ++ { "--library-versions", 0 }, + { "-h", 0 }, + { "--help", 0 }, + { "--list-torrc-options", 0 }, + { "--digests", 0 }, + { "--nt-service", 0 }, + { "-nt-service", 0 }, + { NULL, 0 }, +}; + +/** Helper: Read a list of configuration options from the command line. If + * successful, or if ignore_errors is set, put them in *result, put the + * commandline-only options in *cmdline_result, and return 0; + * otherwise, return -1 and leave *result and cmdline_result + * alone. */ +int +config_parse_commandline(int argc, char **argv, int ignore_errors, + config_line_t **result, + config_line_t **cmdline_result) { + config_line_t *param = NULL; + config_line_t *front = NULL; config_line_t **new = &front; - char *s; + + config_line_t *front_cmdline = NULL; + config_line_t **new_cmdline = &front_cmdline; + + char *s, *arg; int i = 1; while (i < argc) { @@@ -3932,24 -3817,48 +3934,41 @@@ options_init_from_torrc(int argc, char printf("Tor version %s.\n",get_version()); exit(0); } + - if (argc > 1 && (!strcmp(argv[1],"--digests"))) { + if (config_line_find(cmdline_only_options, "--digests")) { printf("Tor version %s.\n",get_version()); printf("%s", libor_get_digests()); printf("%s", tor_get_digests()); exit(0); } - if (argc > 1 && (!strcmp(argv[1],"--library-versions"))) { ++ if (config_line_find(cmdline_only_options, "--library-versions")) { + printf("Tor version %s. \n", get_version()); + printf("Library versions\tCompiled\t\tRuntime\n"); + printf("Libevent\t\t%-15s\t\t%s\n", + tor_libevent_get_header_version_str(), + tor_libevent_get_version_str()); + printf("OpenSSL \t\t%-15s\t\t%s\n", + crypto_openssl_get_header_version_str(), + crypto_openssl_get_version_str()); + printf("Zlib \t\t%-15s\t\t%s\n", + tor_zlib_get_header_version_str(), + tor_zlib_get_version_str()); + //TODO: Hex versions? + exit(0); + } + - /* Go through command-line variables */ - if (!global_cmdline_options) { - /* Or we could redo the list every time we pass this place. - * It does not really matter */ - if (config_get_commandlines(argc, argv, &global_cmdline_options) < 0) { - goto err; - } - } - command = CMD_RUN_TOR; - for (i = 1; i < argc; ++i) { - if (!strcmp(argv[i],"--list-fingerprint")) { + for (p_index = cmdline_only_options; p_index; p_index = p_index->next) { + if (!strcmp(p_index->key,"--list-fingerprint")) { command = CMD_LIST_FINGERPRINT; - } else if (!strcmp(argv[i],"--hash-password")) { + } else if (!strcmp(p_index->key, "--hash-password")) { command = CMD_HASH_PASSWORD; - command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : ""); - ++i; - } else if (!strcmp(argv[i],"--verify-config")) { + command_arg = p_index->value; + } else if (!strcmp(p_index->key, "--dump-config")) { + command = CMD_DUMP_CONFIG; + command_arg = p_index->value; + } else if (!strcmp(p_index->key, "--verify-config")) { command = CMD_VERIFY_CONFIG; } } diff --cc src/or/main.c index ceee29ce66,2d6ca74d8d..ac756de5d2 --- a/src/or/main.c +++ b/src/or/main.c @@@ -2339,28 -2333,19 +2339,29 @@@ tor_init(int argc, char *argv[] addressmap_init(); /* Init the client dns cache. Do it always, since it's * cheap. */ + { /* We search for the "quiet" option first, since it decides whether we * will log anything at all to the command line. */ - for (i=1;inext) { + if (!strcmp(cl->key, "--hush")) + quiet = 1; + if (!strcmp(cl->key, "--quiet") || + !strcmp(cl->key, "--dump-config")) + quiet = 2; - /* --version, --digests, and --help imply --husth */ ++ /* --version, --digests, and --help imply --hush */ + if (!strcmp(cl->key, "--version") || !strcmp(cl->key, "--digests") || + !strcmp(cl->key, "--list-torrc-options") || ++ !strcmp(cl->key, "--library-versions") || + !strcmp(cl->key, "-h") || !strcmp(cl->key, "--help")) + quiet = 1; + } + config_free_lines(opts); + config_free_lines(cmdline_opts); } + /* give it somewhere to log to initially */ switch (quiet) { case 2: