summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-08-10 18:05:20 +0000
committerNick Mathewson <nickm@torproject.org>2005-08-10 18:05:20 +0000
commit16528aa0704501b3dff39a193f5320a809340e3c (patch)
tree73177f65871dd582af4c4e0ab59738c8a8bdac5c
parentc031d14633187038cb3032d557daa64378c54fac (diff)
downloadtor-16528aa0704501b3dff39a193f5320a809340e3c.tar.gz
tor-16528aa0704501b3dff39a193f5320a809340e3c.zip
Add a config-file GETINFO entry; fix a minor memory leak on some SAVECONF calls.
svn:r4761
-rw-r--r--doc/control-spec.txt2
-rw-r--r--src/or/config.c47
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/or.h1
4 files changed, 33 insertions, 19 deletions
diff --git a/doc/control-spec.txt b/doc/control-spec.txt
index 9ce1f60713..830c329cc1 100644
--- a/doc/control-spec.txt
+++ b/doc/control-spec.txt
@@ -294,6 +294,8 @@ $Id$
"version" -- The version of the server's software, including the name
of the software. (example: "Tor 0.0.9.4")
+ "config-file" -- The location of Tor's configuration file ("torrc").
+
"desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest server
descriptor for a given OR, NUL-terminated. If no such OR is known, the
corresponding value is an empty string.
diff --git a/src/or/config.c b/src/or/config.c
index 58a3840898..4b9a2add61 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -322,7 +322,7 @@ static config_format_t state_format = {
/** Command-line and config-file options. */
static or_options_t *global_options = NULL;
/** Name of most recently read torrc file. */
-static char *config_fname = NULL;
+static char *torrc_fname = NULL;
/** Persistant serialized state. */
static or_state_t *global_state = NULL;
/** DOCDOC */
@@ -360,7 +360,7 @@ void
config_free_all(void)
{
config_free(&options_format, global_options);
- tor_free(config_fname);
+ tor_free(torrc_fname);
addr_policy_free(reachable_addr_policy);
reachable_addr_policy = NULL;
}
@@ -2026,16 +2026,16 @@ get_windows_conf_root(void)
#endif
/** Return the default location for our torrc file. */
-static char *
+static const char *
get_default_conf_file(void)
{
#ifdef MS_WINDOWS
- char *path = tor_malloc(MAX_PATH);
+ static char path[MAX_PATH+1];
strlcpy(path, get_windows_conf_root(), MAX_PATH);
strlcat(path,"\\torrc",MAX_PATH);
return path;
#else
- return tor_strdup(CONFDIR "/torrc");
+ return (CONFDIR "/torrc");
#endif
}
@@ -2131,22 +2131,21 @@ options_init_from_torrc(int argc, char **argv)
if (using_default_torrc) {
/* didn't find one, try CONFDIR */
- char *fn;
- fn = get_default_conf_file();
- if (fn && file_status(fn) == FN_FILE) {
- fname = fn;
+ const char *dflt = get_default_conf_file();
+ char *fn = NULL;
+ if (dflt && file_status(dflt) == FN_FILE) {
+ fname = tor_strdup(dflt);
} else {
- tor_free(fn);
#ifndef MS_WINDOWS
fn = expand_filename("~/.torrc");
if (fn && file_status(fn) == FN_FILE) {
fname = fn;
} else {
tor_free(fn);
- fname = get_default_conf_file();
+ fname = tor_strdup(dflt);
}
#else
- fname = get_default_conf_file();
+ fname = tor_strdup(dflt);
#endif
}
}
@@ -2194,8 +2193,8 @@ options_init_from_torrc(int argc, char **argv)
log_fn(LOG_ERR,"Acting on config options left us in a broken state. Dying.");
exit(1);
}
- tor_free(config_fname);
- config_fname = fname;
+ tor_free(torrc_fname);
+ torrc_fname = fname;
return 0;
err:
tor_free(fname);
@@ -2203,6 +2202,18 @@ options_init_from_torrc(int argc, char **argv)
return -1;
}
+/** Return the location for our configuration file.
+ */
+const char *
+get_torrc_fname(void)
+{
+ if (torrc_fname)
+ return torrc_fname;
+ else
+ return get_default_conf_file();
+}
+
+
/** Adjust the address map mased on the MapAddress elements in the
* configuration <b>options</b>
*/
@@ -2818,15 +2829,13 @@ write_configuration_file(const char *fname, or_options_t *options)
int
options_save_current(void)
{
- char *fn;
- if (config_fname) {
+ if (torrc_fname) {
/* XXX This fails if we can't write to our configuration file.
* Arguably, we should try falling back to datadirectory or something.
* But just as arguably, we shouldn't. */
- return write_configuration_file(config_fname, get_options());
+ return write_configuration_file(torrc_fname, get_options());
}
- fn = get_default_conf_file();
- return write_configuration_file(fn, get_options());
+ return write_configuration_file(get_default_conf_file(), get_options());
}
struct unit_table_t {
diff --git a/src/or/control.c b/src/or/control.c
index 7fd4698274..24dda54163 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1150,6 +1150,8 @@ handle_getinfo_helper(const char *question, char **answer)
*answer = NULL; /* unrecognized key by default */
if (!strcmp(question, "version")) {
*answer = tor_strdup(VERSION);
+ } else if (!strcmp(question, "config-file")) {
+ *answer = tor_strdup(get_torrc_fname());
} else if (!strcmpstart(question, "accounting/")) {
return accounting_getinfo_helper(question, answer);
} else if (!strcmpstart(question, "helper-nodes")) {
diff --git a/src/or/or.h b/src/or/or.h
index 77e8e10bf3..53c2cd042a 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1376,6 +1376,7 @@ config_line_t *option_get_assignment(or_options_t *options,
const char *key);
char *options_dump(or_options_t *options, int minimal);
int options_save_current(void);
+const char *get_torrc_fname(void);
or_state_t *get_or_state(void);
int or_state_load(void);