diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-01-12 14:06:14 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-12 14:06:14 -0500 |
commit | 2edfdc02a29e73a01f360f257d8dfe916a7a5b45 (patch) | |
tree | dccbc5984ff04448ef264d9bcdb404e5f0a85b46 /src/or/config.c | |
parent | cacea9102a2431ce8e7e431629a91a43331ac9f9 (diff) | |
parent | f8ffb57bc4430ff9bbd7560eecdda4284b2799ba (diff) | |
download | tor-2edfdc02a29e73a01f360f257d8dfe916a7a5b45.tar.gz tor-2edfdc02a29e73a01f360f257d8dfe916a7a5b45.zip |
Merge remote-tracking branch 'teor/bug13111-empty-key-files-fn-empty'
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/or/config.c b/src/or/config.c index 781f15a42d..beab4bf3a9 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4161,17 +4161,24 @@ find_torrc_filename(config_line_t *cmd_arg, if (*using_default_fname) { /* didn't find one, try CONFDIR */ const char *dflt = get_default_conf_file(defaults_file); - if (dflt && file_status(dflt) == FN_FILE) { + file_status_t st = file_status(dflt); + if (dflt && (st == FN_FILE || st == FN_EMPTY)) { fname = tor_strdup(dflt); } else { #ifndef _WIN32 char *fn = NULL; - if (!defaults_file) + if (!defaults_file) { fn = expand_filename("~/.torrc"); - if (fn && file_status(fn) == FN_FILE) { - fname = fn; + } + if (fn) { + file_status_t hmst = file_status(fn); + if (hmst == FN_FILE || hmst == FN_EMPTY) { + fname = fn; + } else { + tor_free(fn); + fname = tor_strdup(dflt); + } } else { - tor_free(fn); fname = tor_strdup(dflt); } #else @@ -4207,7 +4214,8 @@ load_torrc_from_disk(config_line_t *cmd_arg, int defaults_file) *fname_var = fname; /* Open config file */ - if (file_status(fname) != FN_FILE || + file_status_t st = file_status(fname); + if (!(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) @@ -6466,7 +6474,9 @@ write_configuration_file(const char *fname, const or_options_t *options) tor_assert(fname); 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; |