r12474@Kushana: nickm | 2007-03-06 16:10:05 -0500

We have a PATH_SEPARATOR macro.  How about we use it?


svn:r9782
This commit is contained in:
Nick Mathewson 2007-03-09 21:39:30 +00:00
parent d62e37b4a9
commit 02ce8e6b12
9 changed files with 45 additions and 29 deletions

View File

@ -21,6 +21,11 @@ Changes in version 0.2.0.1-alpha - 2007-??-??
since 0.1.2.2-alpha, and all the servers seem to be using the new since 0.1.2.2-alpha, and all the servers seem to be using the new
eventdns code. eventdns code.
o Minor bufixes (portability):
- Even though windows is equally happy with / and \ as path separators,
try to use \ consistently on windows and / consistently on unix: it
makes the log messages nicer.
Changes in version 0.1.2.10-rc - 2007-03-07 Changes in version 0.1.2.10-rc - 2007-03-07
o Major bugfixes (Windows): o Major bugfixes (Windows):

View File

@ -1549,14 +1549,14 @@ expand_filename(const char *filename)
} }
tor_assert(home); tor_assert(home);
/* Remove trailing slash. */ /* Remove trailing slash. */
if (strlen(home)>1 && !strcmpend(home,"/")) { if (strlen(home)>1 && !strcmpend(home,PATH_SEPARATOR)) {
home[strlen(home)-1] = '\0'; home[strlen(home)-1] = '\0';
} }
/* Plus one for /, plus one for NUL. /* Plus one for /, plus one for NUL.
* Round up to 16 in case we can't do math. */ * Round up to 16 in case we can't do math. */
len = strlen(home)+strlen(rest)+16; len = strlen(home)+strlen(rest)+16;
result = tor_malloc(len); result = tor_malloc(len);
tor_snprintf(result,len,"%s/%s",home,rest?rest:""); tor_snprintf(result,len,"%s"PATH_SEPARATOR"%s",home,rest?rest:"");
tor_free(home); tor_free(home);
return result; return result;
} else { } else {

View File

@ -907,7 +907,8 @@ options_act(or_options_t *old_options)
if (running_tor) { if (running_tor) {
len = strlen(options->DataDirectory)+32; len = strlen(options->DataDirectory)+32;
fn = tor_malloc(len); fn = tor_malloc(len);
tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory); tor_snprintf(fn, len, "%s"PATH_SEPARATOR"cached-status",
options->DataDirectory);
if (check_private_dir(fn, CPD_CREATE) != 0) { if (check_private_dir(fn, CPD_CREATE) != 0) {
log_err(LD_CONFIG, log_err(LD_CONFIG,
"Couldn't access/create private data directory \"%s\"", fn); "Couldn't access/create private data directory \"%s\"", fn);
@ -3516,11 +3517,10 @@ normalize_data_directory(or_options_t *options)
* want. */ * want. */
log_warn(LD_CONFIG, log_warn(LD_CONFIG,
"Default DataDirectory is \"~/.tor\". This expands to " "Default DataDirectory is \"~/.tor\". This expands to "
"\"%s\", which is probably not what you want. Using \"%s/tor\" " "\"%s\", which is probably not what you want. Using "
"instead", fn, LOCALSTATEDIR); "\"%s"PATH_SEPARATOR"tor\" instead", fn, LOCALSTATEDIR);
tor_free(fn); tor_free(fn);
fn = tor_strdup(LOCALSTATEDIR"/tor"); fn = tor_strdup(LOCALSTATEDIR PATH_SEPARATOR "tor");
} }
tor_free(options->DataDirectory); tor_free(options->DataDirectory);
options->DataDirectory = fn; options->DataDirectory = fn;
@ -3933,7 +3933,7 @@ get_or_state_fname(void)
or_options_t *options = get_options(); or_options_t *options = get_options();
size_t len = strlen(options->DataDirectory) + 16; size_t len = strlen(options->DataDirectory) + 16;
fname = tor_malloc(len); fname = tor_malloc(len);
tor_snprintf(fname, len, "%s/state", options->DataDirectory); tor_snprintf(fname, len, "%s"PATH_SEPARATOR"state", options->DataDirectory);
return fname; return fname;
} }

View File

@ -3205,7 +3205,7 @@ init_cookie_authentication(int enabled)
return 0; return 0;
} }
tor_snprintf(fname, sizeof(fname), "%s/control_auth_cookie", tor_snprintf(fname, sizeof(fname), "%s"PATH_SEPARATOR"control_auth_cookie",
get_options()->DataDirectory); get_options()->DataDirectory);
crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN); crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN);
authentication_cookie_is_set = 1; authentication_cookie_is_set = 1;

View File

@ -588,7 +588,7 @@ accounting_record_bandwidth_usage(time_t now, or_state_t *state)
U64_PRINTF_ARG(ROUND_UP(n_bytes_written_in_interval)), U64_PRINTF_ARG(ROUND_UP(n_bytes_written_in_interval)),
(unsigned long)n_seconds_active_in_interval, (unsigned long)n_seconds_active_in_interval,
(unsigned long)expected); (unsigned long)expected);
tor_snprintf(fname, sizeof(fname), "%s/bw_accounting", tor_snprintf(fname, sizeof(fname), "%s"PATH_SEPARATOR"bw_accounting",
get_options()->DataDirectory); get_options()->DataDirectory);
if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) { if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) {
r = write_str_to_file(fname, buf, 0); r = write_str_to_file(fname, buf, 0);

View File

@ -1189,7 +1189,7 @@ do_hup(void)
router_rebuild_descriptor(1); router_rebuild_descriptor(1);
descriptor = router_get_my_descriptor(); descriptor = router_get_my_descriptor();
if (descriptor) { if (descriptor) {
tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"router.desc",
options->DataDirectory); options->DataDirectory);
log_info(LD_OR,"Saving descriptor to \"%s\"...",keydir); log_info(LD_OR,"Saving descriptor to \"%s\"...",keydir);
if (write_str_to_file(keydir, descriptor, 0)) { if (write_str_to_file(keydir, descriptor, 0)) {

View File

@ -344,7 +344,8 @@ rend_service_load_keys(void)
/* Load key */ /* Load key */
if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) || if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) ||
strlcat(fname,"/private_key",sizeof(fname)) >= sizeof(fname)) { strlcat(fname,PATH_SEPARATOR"private_key",sizeof(fname))
>= sizeof(fname)) {
log_warn(LD_CONFIG, "Directory name too long to store key file: \"%s\".", log_warn(LD_CONFIG, "Directory name too long to store key file: \"%s\".",
s->directory); s->directory);
return -1; return -1;
@ -363,7 +364,8 @@ rend_service_load_keys(void)
return -1; return -1;
} }
if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) || if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) ||
strlcat(fname,"/hostname",sizeof(fname)) >= sizeof(fname)) { strlcat(fname,PATH_SEPARATOR"hostname",sizeof(fname))
>= sizeof(fname)) {
log_warn(LD_CONFIG, "Directory name too long to store hostname file:" log_warn(LD_CONFIG, "Directory name too long to store hostname file:"
" \"%s\".", s->directory); " \"%s\".", s->directory);
return -1; return -1;

View File

@ -133,9 +133,11 @@ rotate_onion_key(void)
or_state_t *state = get_or_state(); or_state_t *state = get_or_state();
time_t now; time_t now;
tor_snprintf(fname,sizeof(fname), tor_snprintf(fname,sizeof(fname),
"%s/keys/secret_onion_key",get_options()->DataDirectory); "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key",
get_options()->DataDirectory);
tor_snprintf(fname_prev,sizeof(fname_prev), tor_snprintf(fname_prev,sizeof(fname_prev),
"%s/keys/secret_onion_key.old",get_options()->DataDirectory); "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key.old",
get_options()->DataDirectory);
if (!(prkey = crypto_new_pk_env())) { if (!(prkey = crypto_new_pk_env())) {
log_err(LD_GENERAL,"Error constructing rotated onion key"); log_err(LD_GENERAL,"Error constructing rotated onion key");
goto error; goto error;
@ -267,19 +269,21 @@ init_keys(void)
return -1; return -1;
} }
/* Check the key directory. */ /* Check the key directory. */
tor_snprintf(keydir,sizeof(keydir),"%s/keys", datadir); tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"keys", datadir);
if (check_private_dir(keydir, CPD_CREATE)) { if (check_private_dir(keydir, CPD_CREATE)) {
return -1; return -1;
} }
/* 1. Read identity key. Make it if none is found. */ /* 1. Read identity key. Make it if none is found. */
tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_id_key",datadir); tor_snprintf(keydir,sizeof(keydir),
"%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_id_key",datadir);
log_info(LD_GENERAL,"Reading/making identity key \"%s\"...",keydir); log_info(LD_GENERAL,"Reading/making identity key \"%s\"...",keydir);
prkey = init_key_from_file(keydir); prkey = init_key_from_file(keydir);
if (!prkey) return -1; if (!prkey) return -1;
set_identity_key(prkey); set_identity_key(prkey);
/* 2. Read onion key. Make it if none is found. */ /* 2. Read onion key. Make it if none is found. */
tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key",datadir); tor_snprintf(keydir,sizeof(keydir),
"%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key",datadir);
log_info(LD_GENERAL,"Reading/making onion key \"%s\"...",keydir); log_info(LD_GENERAL,"Reading/making onion key \"%s\"...",keydir);
prkey = init_key_from_file(keydir); prkey = init_key_from_file(keydir);
if (!prkey) return -1; if (!prkey) return -1;
@ -295,7 +299,8 @@ init_keys(void)
or_state_mark_dirty(state, options->AvoidDiskWrites ? time(NULL)+3600 : 0); or_state_mark_dirty(state, options->AvoidDiskWrites ? time(NULL)+3600 : 0);
} }
tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key.old",datadir); tor_snprintf(keydir,sizeof(keydir),
"%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key.old",datadir);
if (file_status(keydir) == FN_FILE) { if (file_status(keydir) == FN_FILE) {
prkey = init_key_from_file(keydir); prkey = init_key_from_file(keydir);
if (prkey) if (prkey)
@ -330,7 +335,7 @@ init_keys(void)
} }
/* 5. Dump fingerprint to 'fingerprint' */ /* 5. Dump fingerprint to 'fingerprint' */
tor_snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir); tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"fingerprint", datadir);
log_info(LD_GENERAL,"Dumping fingerprint to \"%s\"...",keydir); log_info(LD_GENERAL,"Dumping fingerprint to \"%s\"...",keydir);
if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) { if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) {
log_err(LD_GENERAL,"Error computing fingerprint"); log_err(LD_GENERAL,"Error computing fingerprint");

View File

@ -125,7 +125,7 @@ router_reload_networkstatus(void)
if (!networkstatus_list) if (!networkstatus_list)
networkstatus_list = smartlist_create(); networkstatus_list = smartlist_create();
tor_snprintf(filename,sizeof(filename),"%s/cached-status", tor_snprintf(filename,sizeof(filename),"%s"PATH_SEPARATOR"cached-status",
get_options()->DataDirectory); get_options()->DataDirectory);
entries = tor_listdir(filename); entries = tor_listdir(filename);
SMARTLIST_FOREACH(entries, const char *, fn, { SMARTLIST_FOREACH(entries, const char *, fn, {
@ -136,7 +136,8 @@ router_reload_networkstatus(void)
"Skipping cached-status file with unexpected name \"%s\"",fn); "Skipping cached-status file with unexpected name \"%s\"",fn);
continue; continue;
} }
tor_snprintf(filename,sizeof(filename),"%s/cached-status/%s", tor_snprintf(filename,sizeof(filename),
"%s"PATH_SEPARATOR"cached-status"PATH_SEPARATOR"%s",
get_options()->DataDirectory, fn); get_options()->DataDirectory, fn);
s = read_file_to_str(filename, 0, &st); s = read_file_to_str(filename, 0, &st);
if (s) { if (s) {
@ -196,7 +197,7 @@ router_append_to_journal(signed_descriptor_t *desc)
const char *body = signed_descriptor_get_body(desc); const char *body = signed_descriptor_get_body(desc);
size_t len = desc->signed_descriptor_len; size_t len = desc->signed_descriptor_len;
tor_snprintf(fname, fname_len, "%s/cached-routers.new", tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
options->DataDirectory); options->DataDirectory);
tor_assert(len == strlen(body)); tor_assert(len == strlen(body));
@ -264,8 +265,9 @@ router_rebuild_store(int force)
fname_len = strlen(options->DataDirectory)+32; fname_len = strlen(options->DataDirectory)+32;
fname = tor_malloc(fname_len); fname = tor_malloc(fname_len);
fname_tmp = tor_malloc(fname_len); fname_tmp = tor_malloc(fname_len);
tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory); tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers",
tor_snprintf(fname_tmp, fname_len, "%s/cached-routers.tmp", options->DataDirectory);
tor_snprintf(fname_tmp, fname_len, "%s"PATH_SEPARATOR"cached-routers.tmp",
options->DataDirectory); options->DataDirectory);
chunk_list = smartlist_create(); chunk_list = smartlist_create();
@ -331,7 +333,7 @@ router_rebuild_store(int force)
}); });
} }
tor_snprintf(fname, fname_len, "%s/cached-routers.new", tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
options->DataDirectory); options->DataDirectory);
write_str_to_file(fname, "", 1); write_str_to_file(fname, "", 1);
@ -364,7 +366,8 @@ router_reload_router_list(void)
router_journal_len = router_store_len = 0; router_journal_len = router_store_len = 0;
tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory); tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers",
options->DataDirectory);
if (routerlist->mmap_descriptors) /* get rid of it first */ if (routerlist->mmap_descriptors) /* get rid of it first */
tor_munmap_file(routerlist->mmap_descriptors); tor_munmap_file(routerlist->mmap_descriptors);
@ -376,7 +379,7 @@ router_reload_router_list(void)
SAVED_IN_CACHE, NULL); SAVED_IN_CACHE, NULL);
} }
tor_snprintf(fname, fname_len, "%s/cached-routers.new", tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
options->DataDirectory); options->DataDirectory);
if (file_status(fname) == FN_FILE) if (file_status(fname) == FN_FILE)
contents = read_file_to_str(fname, RFTS_BIN|RFTS_IGNORE_MISSING, NULL); contents = read_file_to_str(fname, RFTS_BIN|RFTS_IGNORE_MISSING, NULL);
@ -2352,7 +2355,8 @@ networkstatus_get_cache_filename(const char *identity_digest)
char fp[HEX_DIGEST_LEN+1]; char fp[HEX_DIGEST_LEN+1];
char *fn = tor_malloc(len+1); char *fn = tor_malloc(len+1);
base16_encode(fp, HEX_DIGEST_LEN+1, identity_digest, DIGEST_LEN); base16_encode(fp, HEX_DIGEST_LEN+1, identity_digest, DIGEST_LEN);
tor_snprintf(fn, len, "%s/cached-status/%s",datadir,fp); tor_snprintf(fn, len, "%s"PATH_SEPARATOR"cached-status"PATH_SEPARATOR"%s",
datadir,fp);
return fn; return fn;
} }