summaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-09-13 12:36:55 -0400
committerNick Mathewson <nickm@torproject.org>2013-09-13 12:36:55 -0400
commite35c972851686b5f6f2181e4eddb592f07fd7587 (patch)
tree359d389cf71396cc8d7a640fc18b89eb87134489 /src/or/main.c
parente0b2cd061bd62fc790d434b2da7ecc51ed100904 (diff)
parentbf5e1e19f7c65845543001a18b8277c7a906814c (diff)
downloadtor-e35c972851686b5f6f2181e4eddb592f07fd7587.tar.gz
tor-e35c972851686b5f6f2181e4eddb592f07fd7587.zip
Merge branch 'bug4647_squashed'
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/or/main.c b/src/or/main.c
index fa112437fe..ceee29ce66 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -21,6 +21,7 @@
#include "circuituse.h"
#include "command.h"
#include "config.h"
+#include "confparse.h"
#include "connection.h"
#include "connection_edge.h"
#include "connection_or.h"
@@ -2325,7 +2326,7 @@ int
tor_init(int argc, char *argv[])
{
char buf[256];
- int i, quiet = 0;
+ int quiet = 0;
time_of_process_start = time(NULL);
init_connection_lists();
/* Have the log set up with our application name. */
@@ -2338,17 +2339,28 @@ 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;i<argc;++i) {
- if (!strcmp(argv[i], "--hush"))
- quiet = 1;
- if (!strcmp(argv[i], "--quiet"))
- quiet = 2;
- /* --version implies --quiet */
- if (!strcmp(argv[i], "--version"))
- quiet = 2;
+ config_line_t *opts = NULL, *cmdline_opts = NULL;
+ const config_line_t *cl;
+ (void) config_parse_commandline(argc, argv, 1, &opts, &cmdline_opts);
+ for (cl = cmdline_opts; cl; cl = cl->next) {
+ 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 */
+ if (!strcmp(cl->key, "--version") || !strcmp(cl->key, "--digests") ||
+ !strcmp(cl->key, "--list-torrc-options") ||
+ !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:
@@ -2592,7 +2604,7 @@ do_list_fingerprint(void)
const char *nickname = get_options()->Nickname;
if (!server_mode(get_options())) {
log_err(LD_GENERAL,
- "Clients don't have long-term identity keys. Exiting.\n");
+ "Clients don't have long-term identity keys. Exiting.");
return -1;
}
tor_assert(nickname);
@@ -2630,6 +2642,34 @@ do_hash_password(void)
printf("16:%s\n",output);
}
+/** Entry point for configuration dumping: write the configuration to
+ * stdout. */
+static int
+do_dump_config(void)
+{
+ const or_options_t *options = get_options();
+ const char *arg = options->command_arg;
+ int how;
+ char *opts;
+ if (!strcmp(arg, "short")) {
+ how = OPTIONS_DUMP_MINIMAL;
+ } else if (!strcmp(arg, "non-builtin")) {
+ how = OPTIONS_DUMP_DEFAULTS;
+ } else if (!strcmp(arg, "full")) {
+ how = OPTIONS_DUMP_ALL;
+ } else {
+ printf("%s is not a recognized argument to --dump-config. "
+ "Please select 'short', 'non-builtin', or 'full'", arg);
+ return -1;
+ }
+
+ opts = options_dump(options, how);
+ printf("%s", opts);
+ tor_free(opts);
+
+ return 0;
+}
+
#if defined (WINCE)
int
find_flashcard_path(PWCHAR path, size_t size)
@@ -2844,6 +2884,9 @@ tor_main(int argc, char *argv[])
printf("Configuration was valid\n");
result = 0;
break;
+ case CMD_DUMP_CONFIG:
+ result = do_dump_config();
+ break;
case CMD_RUN_UNITTESTS: /* only set by test.c */
default:
log_warn(LD_BUG,"Illegal command number %d: internal error.",