diff --git a/src/or/config.c b/src/or/config.c index dc2a1ec2b0..6ce47263bd 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -945,10 +945,13 @@ const char *get_data_directory(or_options_t *options) { const char *d; if (options->DataDirectory) d = options->DataDirectory; - else + else if (server_mode()) d = "~/.tor"; + else + d = NULL; /* XXX008 don't create datadir until we have something + we'll be putting in it */ - if (strncmp(d,"~/",2)==0) { + if (d && strncmp(d,"~/",2)==0) { char *fn = expand_filename(d); tor_free(options->DataDirectory); options->DataDirectory = fn; diff --git a/src/or/dirserv.c b/src/or/dirserv.c index cbdfb6b0a7..5351c74931 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -673,9 +673,11 @@ size_t dirserv_get_directory(const char **directory) exit(0); } free(new_directory); - sprintf(filename,"%s/cached-directory", get_data_directory(&options)); - if(write_str_to_file(filename,the_directory) < 0) { - log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring."); + if(get_data_directory(&options)) { + sprintf(filename,"%s/cached-directory", get_data_directory(&options)); + if(write_str_to_file(filename,the_directory) < 0) { + log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring."); + } } } else { log(LOG_INFO,"Directory still clean, reusing."); diff --git a/src/or/main.c b/src/or/main.c index 640edffe75..054097b7fb 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -667,7 +667,8 @@ static int init_from_config(int argc, char **argv) { } /* Ensure data directory is private; create if possible. */ - if (check_private_dir(get_data_directory(&options), 1) != 0) { + if (get_data_directory(&options) && + check_private_dir(get_data_directory(&options), 1) != 0) { log_fn(LOG_ERR, "Couldn't access/create private data directory %s", get_data_directory(&options)); return -1;