diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-08-26 23:22:27 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-08-26 23:22:27 +0000 |
commit | 26d2301c765799e4d41dc437996f3d26ba506482 (patch) | |
tree | c658e1c7d97c82dd8bdab7f407f6a60aa5279159 /src | |
parent | cd2bb915edd42715055b375b26aa6cf9a89f281f (diff) | |
download | tor-26d2301c765799e4d41dc437996f3d26ba506482.tar.gz tor-26d2301c765799e4d41dc437996f3d26ba506482.zip |
Make unit tests (and others) run without launching listeners, creating subdirectories, and so on.
svn:r4876
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 31 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/test.c | 4 |
3 files changed, 23 insertions, 14 deletions
diff --git a/src/or/config.c b/src/or/config.c index 642fb30ab5..19a5f8b6f1 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -411,9 +411,10 @@ options_act(or_options_t *old_options) char *fn; size_t len; or_options_t *options = get_options(); + int running_tor = options->command == CMD_RUN_TOR; static int libevent_initialized = 0; - if (options->RunAsDaemon) { + if (running_tor && options->RunAsDaemon) { start_daemon(); } @@ -426,7 +427,7 @@ options_act(or_options_t *old_options) } } - if (rend_config_services(options, 0)<0) { + if (running_tor && rend_config_services(options, 0)<0) { log_fn(LOG_ERR, "Bug: Previously validated hidden services line could not be added!"); return -1; @@ -448,15 +449,18 @@ options_act(or_options_t *old_options) options->DataDirectory); return -1; } - len = strlen(options->DataDirectory)+32; - fn = tor_malloc(len); - tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory); - if (check_private_dir(fn, CPD_CREATE) != 0) { - log_fn(LOG_ERR, "Couldn't access/create private data directory \"%s\"",fn); + if (running_tor) { + len = strlen(options->DataDirectory)+32; + fn = tor_malloc(len); + tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory); + if (check_private_dir(fn, CPD_CREATE) != 0) { + log_fn(LOG_ERR, "Couldn't access/create private data directory \"%s\"", + fn); + tor_free(fn); + return -1; + } tor_free(fn); - return -1; } - tor_free(fn); /* Bail out at this point if we're not going to be a client or server: * we want to not fork, and to log stuff to stderr. */ @@ -474,7 +478,7 @@ options_act(or_options_t *old_options) control_adjust_event_log_severity(); /* Set up libevent. */ - if (!libevent_initialized) { + if (running_tor && !libevent_initialized) { if (init_libevent()) return -1; libevent_initialized = 1; @@ -500,14 +504,14 @@ options_act(or_options_t *old_options) } /* Finish backgrounding the process */ - if (options->RunAsDaemon) { + if (running_tor && options->RunAsDaemon) { /* We may be calling this for the n'th time (on SIGHUP), but it's safe. */ finish_daemon(options->DataDirectory); } /* Write our pid to the pid file. If we do not have write permissions we * will log a warning */ - if (options->PidFile) + if (running_tor && options->PidFile) write_pidfile(options->PidFile); /* Register addressmap directives */ @@ -534,6 +538,9 @@ options_act(or_options_t *old_options) if (accounting_is_enabled(options)) configure_accounting(time(NULL)); + if (!running_tor) + return 0; + if (!we_are_hibernating() && retry_all_listeners(0) < 0) { log_fn(LOG_ERR,"Failed to bind one of the listener ports."); return -1; diff --git a/src/or/or.h b/src/or/or.h index eb699afdd7..31f3828172 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1034,7 +1034,7 @@ typedef struct { /** What should the tor process actually do? */ enum { CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT, CMD_HASH_PASSWORD, - CMD_VERIFY_CONFIG, + CMD_VERIFY_CONFIG, CMD_RUN_UNITTESTS } command; const char *command_arg; /**< Argument for command-line option. */ diff --git a/src/or/test.c b/src/or/test.c index 4a91399a28..067cb9c6c1 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -114,7 +114,8 @@ remove_directory(void) /* Only "." and ".." start with ., since we don't create any dotfiles. */ if (de->d_name[0] == '.') continue; if (unlink(get_fname(de->d_name))) { - perror("Error removing file"); + printf("Couldn't remove temprorary file \"%s/%s\"",temp_dir,de->d_name); + perror(""); } #if 0 printf("==%s\n", de->d_name); @@ -1522,6 +1523,7 @@ int main(int c, char**v) { or_options_t *options = options_new(); + options->command = CMD_RUN_UNITTESTS; network_init(); setup_directory(); options_init(options); |