Make unit tests (and others) run without launching listeners, creating subdirectories, and so on.

svn:r4876
This commit is contained in:
Nick Mathewson 2005-08-26 23:22:27 +00:00
parent cd2bb915ed
commit 26d2301c76
3 changed files with 23 additions and 14 deletions

View file

@ -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;

View file

@ -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. */

View file

@ -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);