[tor-commits] [tor/master] Merge remote-tracking branch 'public/ticket13037'
nickm at torproject.org
nickm at torproject.org
Sun Jan 18 21:07:16 UTC 2015
commit 63765399eb844adfa877a288e655eb281ac8c988
Merge: 5aa55a1 ffa4ed8
Author: Nick Mathewson <nickm at torproject.org>
Date: Sun Jan 18 16:07:08 2015 -0500
Merge remote-tracking branch 'public/ticket13037'
Conflicts:
src/or/config.c
changes/remove-bad-fp | 4 ++++
changes/ticket13037 | 4 ++++
configure.ac | 7 +++++++
src/or/config.c | 32 ++++++++++++++------------------
src/or/control.c | 8 ++++++--
5 files changed, 35 insertions(+), 20 deletions(-)
diff --cc src/or/config.c
index 1995cb7,b9a567b..64bc54b
--- a/src/or/config.c
+++ b/src/or/config.c
@@@ -4178,22 -4148,16 +4181,22 @@@ find_torrc_filename(config_line_t *cmd_
} else {
#ifndef _WIN32
char *fn = NULL;
- if (!defaults_file)
+ if (!defaults_file) {
fn = expand_filename("~/.torrc");
- if (fn && (file_status(fn) == FN_FILE || dflt == NULL)) {
- fname = fn;
+ }
+ if (fn) {
+ file_status_t hmst = file_status(fn);
- if (hmst == FN_FILE || hmst == FN_EMPTY) {
++ if (hmst == FN_FILE || hmst == FN_EMPTY || dflt == NULL) {
+ fname = fn;
+ } else {
+ tor_free(fn);
+ fname = tor_strdup(dflt);
+ }
} else {
- fname = tor_strdup(dflt);
- tor_free(fn);
+ fname = dflt ? tor_strdup(dflt) : NULL;
}
#else
- fname = tor_strdup(dflt);
+ fname = dflt ? tor_strdup(dflt) : NULL;
#endif
}
}
@@@ -4216,20 -4180,17 +4219,20 @@@ load_torrc_from_disk(config_line_t *cmd
int ignore_missing_torrc = 0;
char **fname_var = defaults_file ? &torrc_defaults_fname : &torrc_fname;
- fname = find_torrc_filename(cmd_arg, defaults_file,
- &using_default_torrc, &ignore_missing_torrc);
-
+ if (*fname_var == NULL) {
+ fname = find_torrc_filename(cmd_arg, defaults_file,
+ &using_default_torrc, &ignore_missing_torrc);
- tor_assert(fname);
+ tor_free(*fname_var);
+ *fname_var = fname;
+ } else {
+ fname = *fname_var;
+ }
- log_debug(LD_CONFIG, "Opening config file \"%s\"", fname);
+ log_debug(LD_CONFIG, "Opening config file \"%s\"", fname?fname:"<NULL>");
- tor_free(*fname_var);
- *fname_var = fname;
-
/* Open config file */
- file_status_t st = file_status(fname);
- if (!(st == FN_FILE || st == FN_EMPTY) ||
++ file_status_t st = fname ? file_status(fname) : FN_EMPTY;
+ if (fname == NULL ||
- file_status(fname) != FN_FILE ||
++ !(st == FN_FILE || st == FN_EMPTY) ||
!(cf = read_file_to_str(fname,0,NULL))) {
if (using_default_torrc == 1 || ignore_missing_torrc) {
if (!defaults_file)
@@@ -6559,12 -6438,11 +6554,13 @@@ write_configuration_file(const char *fn
char *old_val=NULL, *new_val=NULL, *new_conf=NULL;
int rename_old = 0, r;
- tor_assert(fname);
+ if (!fname)
+ return -1;
switch (file_status(fname)) {
+ /* create backups of old config files, even if they're empty */
case FN_FILE:
+ case FN_EMPTY:
old_val = read_file_to_str(fname, 0, NULL);
if (!old_val || strcmpstart(old_val, GENERATED_FILE_PREFIX)) {
rename_old = 1;
diff --cc src/or/control.c
index 9ff71c9,a569c96..00cb431
--- a/src/or/control.c
+++ b/src/or/control.c
@@@ -1438,12 -1438,14 +1438,16 @@@ getinfo_helper_misc(control_connection_
(void) conn;
if (!strcmp(question, "version")) {
*answer = tor_strdup(get_version());
+ } else if (!strcmp(question, "bw-event-cache")) {
+ *answer = get_bw_samples();
} else if (!strcmp(question, "config-file")) {
- *answer = tor_strdup(get_torrc_fname(0));
+ const char *a = get_torrc_fname(0);
+ if (a)
+ *answer = tor_strdup(a);
} else if (!strcmp(question, "config-defaults-file")) {
- *answer = tor_strdup(get_torrc_fname(1));
+ const char *a = get_torrc_fname(1);
+ if (a)
+ *answer = tor_strdup(a);
} else if (!strcmp(question, "config-text")) {
*answer = options_dump(get_options(), OPTIONS_DUMP_MINIMAL);
} else if (!strcmp(question, "info/names")) {
More information about the tor-commits
mailing list