diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 53 | ||||
-rw-r--r-- | src/or/or.h | 2 |
2 files changed, 39 insertions, 16 deletions
diff --git a/src/or/config.c b/src/or/config.c index 137704508f..8d82c1678e 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -3627,21 +3627,18 @@ load_torrc_from_disk(int argc, char **argv) int options_init_from_torrc(int argc, char **argv) { - or_options_t *oldoptions, *newoptions = NULL; - config_line_t *cl; - char *cf=NULL, *errmsg=NULL; - int i, retval; + char *cf=NULL; + int i, retval, command; static char **backup_argv; static int backup_argc; + char *command_arg = NULL; if (argv) { /* first time we're called. save commandline args */ backup_argv = argv; backup_argc = argc; - oldoptions = NULL; } else { /* we're reloading. need to clean up old options first. */ argv = backup_argv; argc = backup_argc; - oldoptions = get_options(); } if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) { print_usage(); @@ -3670,20 +3667,16 @@ 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; - + command = CMD_RUN_TOR; for (i = 1; i < argc; ++i) { if (!strcmp(argv[i],"--list-fingerprint")) { - newoptions->command = CMD_LIST_FINGERPRINT; + 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] : ""); + command = CMD_HASH_PASSWORD; + command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : ""); ++i; } else if (!strcmp(argv[i],"--verify-config")) { - newoptions->command = CMD_VERIFY_CONFIG; + command = CMD_VERIFY_CONFIG; } } @@ -3691,9 +3684,36 @@ options_init_from_torrc(int argc, char **argv) if (!cf) goto err; + retval = options_init_from_string(cf, command, command_arg); + tor_free(cf); + if (retval < 0) + goto err; + + return 0; + + err: + return -1; +} + +int +options_init_from_string(const char *cf, int command, const char *command_arg) +{ + or_options_t *oldoptions, *newoptions; + config_line_t *cl; + int retval; + char *errmsg=NULL; + + oldoptions = global_options; /* get_options unfortunately asserts if + this is the first time we run*/ + + newoptions = tor_malloc_zero(sizeof(or_options_t)); + newoptions->_magic = OR_OPTIONS_MAGIC; + options_init(newoptions); + newoptions->command = command; + newoptions->command_arg = command_arg; + /* get config lines, assign them */ retval = config_get_lines(cf, &cl); - tor_free(cf); if (retval < 0) goto err; retval = config_assign(&options_format, newoptions, cl, 0, 0, &errmsg); @@ -3718,6 +3738,7 @@ options_init_from_torrc(int argc, char **argv) goto err; /* frees and replaces old options */ return 0; + err: config_free(&options_format, newoptions); if (errmsg) { diff --git a/src/or/or.h b/src/or/or.h index 4f30f58203..ca36dbc024 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2652,6 +2652,8 @@ int resolve_my_address(int warn_severity, or_options_t *options, int is_local_IP(uint32_t ip) ATTR_PURE; void options_init(or_options_t *options); int options_init_from_torrc(int argc, char **argv); +int options_init_from_string(const char *cf, + int command, const char *command_arg); int option_is_recognized(const char *key); const char *option_get_canonical_name(const char *key); config_line_t *option_get_assignment(or_options_t *options, |