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
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
o Major bugfixes (Windows):

View File

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

View File

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

View File

@ -3205,7 +3205,7 @@ init_cookie_authentication(int enabled)
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);
crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN);
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)),
(unsigned long)n_seconds_active_in_interval,
(unsigned long)expected);
tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
tor_snprintf(fname, sizeof(fname), "%s"PATH_SEPARATOR"bw_accounting",
get_options()->DataDirectory);
if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) {
r = write_str_to_file(fname, buf, 0);

View File

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

View File

@ -344,7 +344,8 @@ rend_service_load_keys(void)
/* Load key */
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\".",
s->directory);
return -1;
@ -363,7 +364,8 @@ rend_service_load_keys(void)
return -1;
}
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:"
" \"%s\".", s->directory);
return -1;

View File

@ -133,9 +133,11 @@ rotate_onion_key(void)
or_state_t *state = get_or_state();
time_t now;
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),
"%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())) {
log_err(LD_GENERAL,"Error constructing rotated onion key");
goto error;
@ -267,19 +269,21 @@ init_keys(void)
return -1;
}
/* 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)) {
return -1;
}
/* 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);
prkey = init_key_from_file(keydir);
if (!prkey) return -1;
set_identity_key(prkey);
/* 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);
prkey = init_key_from_file(keydir);
if (!prkey) return -1;
@ -295,7 +299,8 @@ init_keys(void)
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) {
prkey = init_key_from_file(keydir);
if (prkey)
@ -330,7 +335,7 @@ init_keys(void)
}
/* 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);
if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) {
log_err(LD_GENERAL,"Error computing fingerprint");

View File

@ -125,7 +125,7 @@ router_reload_networkstatus(void)
if (!networkstatus_list)
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);
entries = tor_listdir(filename);
SMARTLIST_FOREACH(entries, const char *, fn, {
@ -136,7 +136,8 @@ router_reload_networkstatus(void)
"Skipping cached-status file with unexpected name \"%s\"",fn);
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);
s = read_file_to_str(filename, 0, &st);
if (s) {
@ -196,7 +197,7 @@ router_append_to_journal(signed_descriptor_t *desc)
const char *body = signed_descriptor_get_body(desc);
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);
tor_assert(len == strlen(body));
@ -264,8 +265,9 @@ router_rebuild_store(int force)
fname_len = strlen(options->DataDirectory)+32;
fname = tor_malloc(fname_len);
fname_tmp = tor_malloc(fname_len);
tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory);
tor_snprintf(fname_tmp, fname_len, "%s/cached-routers.tmp",
tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers",
options->DataDirectory);
tor_snprintf(fname_tmp, fname_len, "%s"PATH_SEPARATOR"cached-routers.tmp",
options->DataDirectory);
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);
write_str_to_file(fname, "", 1);
@ -364,7 +366,8 @@ router_reload_router_list(void)
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 */
tor_munmap_file(routerlist->mmap_descriptors);
@ -376,7 +379,7 @@ router_reload_router_list(void)
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);
if (file_status(fname) == FN_FILE)
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 *fn = tor_malloc(len+1);
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;
}