char *fn = NULL;
if (!defaults_file)
fn = expand_filename("~/.torrc");
- if (fn && file_status(fn) == FN_FILE) {
+ if (fn && (file_status(fn) == FN_FILE || dflt == NULL)) {
fname = fn;
} else {
tor_free(fn);
- fname = tor_strdup(dflt);
+ fname = dflt ? tor_strdup(dflt) : NULL;
}
#else
- fname = tor_strdup(dflt);
+ fname = dflt ? tor_strdup(dflt) : NULL;
#endif
}
}
fname = find_torrc_filename(cmd_arg, defaults_file,
&using_default_torrc, &ignore_missing_torrc);
- tor_assert(fname);
- 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 */
- if (file_status(fname) != FN_FILE ||
+ if (fname == NULL ||
+ file_status(fname) != FN_FILE ||
!(cf = read_file_to_str(fname,0,NULL))) {
if (using_default_torrc == 1 || ignore_missing_torrc) {
if (!defaults_file)
return err;
}
-/** Return the location for our configuration file.
+/** Return the location for our configuration file. May return NULL.
*/
const char *
get_torrc_fname(int defaults_fname)
char *old_val=NULL, *new_val=NULL, *new_conf=NULL;
int rename_old = 0, r;
+ if (!fname)
+ return -1;
+
tor_assert(fname);
switch (file_status(fname)) {
if (!strcmp(question, "version")) {
*answer = tor_strdup(get_version());
} else if (!strcmp(question, "config-file")) {
- *answer = tor_strdup(get_torrc_fname(0));
+ if (get_torrc_fname(0))
+ *answer = tor_strdup(get_torrc_fname(0));
} else if (!strcmp(question, "config-defaults-file")) {
- *answer = tor_strdup(get_torrc_fname(1));
+ if (get_torrc_fname(1))
+ *answer = tor_strdup(get_torrc_fname(1));
} else if (!strcmp(question, "config-text")) {
*answer = options_dump(get_options(), OPTIONS_DUMP_MINIMAL);
} else if (!strcmp(question, "info/names")) {