[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Add a config-file GETINFO entry; fix a minor memory leak on...



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv16767/src/or

Modified Files:
	config.c control.c or.h 
Log Message:
Add a config-file GETINFO entry; fix a minor memory leak on some SAVECONF calls.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.384
retrieving revision 1.385
diff -u -d -r1.384 -r1.385
--- config.c	9 Aug 2005 18:49:43 -0000	1.384
+++ config.c	10 Aug 2005 18:05:20 -0000	1.385
@@ -322,7 +322,7 @@
 /** 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 @@
 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 @@
 #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 @@
 
   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 @@
     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 @@
   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 @@
 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 {

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- control.c	9 Aug 2005 05:16:29 -0000	1.116
+++ control.c	10 Aug 2005 18:05:20 -0000	1.117
@@ -1150,6 +1150,8 @@
   *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")) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.639
retrieving revision 1.640
diff -u -d -r1.639 -r1.640
--- or.h	9 Aug 2005 05:22:23 -0000	1.639
+++ or.h	10 Aug 2005 18:05:20 -0000	1.640
@@ -1376,6 +1376,7 @@
                                      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);