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

[or-cvs] Look in .torrc if no CONFDIR "torrc" is found.



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv30767/src/or

Modified Files:
	config.c 
Log Message:
Look in .torrc if no CONFDIR "torrc" is found.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- config.c	13 Jul 2004 18:23:40 -0000	1.125
+++ config.c	16 Jul 2004 19:43:58 -0000	1.126
@@ -607,10 +607,20 @@
     i++;
   }
   if(i < argc-1) { /* we found one */
-    fname = argv[i+1];
+    fname = tor_strdup(argv[i+1]);
     using_default_torrc = 0;
-  } else { /* didn't find one, try CONFDIR */
-    fname = CONFDIR "/torrc";
+  } else if (file_status(CONFDIR "/torrc")==FN_FILE) {
+    /* didn't find one, try CONFDIR */
+    fname = tor_strdup(CONFDIR "/torrc");
+    using_default_torrc = 1;
+  } else {
+    char *fn = expand_filename("~/.torrc");
+    if (file_status(fn)==FN_FILE) {
+      fname = fn;
+    } else {
+      tor_free(fn);
+      fname = tor_strdup(CONFDIR "/torrc");
+    }
     using_default_torrc = 1;
   }
   log(LOG_DEBUG,"Opening config file '%s'",fname);
@@ -619,13 +629,17 @@
   if(!cf) {
     if(using_default_torrc == 1) {
       log(LOG_NOTICE, "Configuration file '%s' not present, using reasonable defaults.",fname);
-      if(config_assign_defaults(options) < 0)
+      tor_free(fname);
+      if(config_assign_defaults(options) < 0) {
         return -1;
+      }
     } else {
       log(LOG_WARN, "Unable to open configuration file '%s'.",fname);
+      tor_free(fname);
       return -1;
     }
   } else { /* it opened successfully. use it. */
+    tor_free(fname);
     cl = config_get_lines(cf);
     if(!cl) return -1;
     if(config_assign(options,cl) < 0)
@@ -925,27 +939,15 @@
 
 const char *get_data_directory(or_options_t *options) {
   const char *d;
-  char buf[1024];
-  const char *home;
-  size_t n;
   if (options->DataDirectory)
     d = options->DataDirectory;
   else
     d = "~/.tor";
 
-  if (!strncmp(d,"~/",2)) {
-    home = getenv("HOME");
-    if (!home) {
-      log_fn(LOG_ERR, "Couldn't find $HOME environment variable for data directory %s", d);
-      exit(1);
-    }
-    n = snprintf(buf,1020,"%s/%s",home,d+2);
-    if (n>=1020) {
-      log_fn(LOG_ERR, "Overlong data directory name.");
-      exit(1);
-    }
+  if (strncmp(d,"~/",2)==0) {
+    char *fn = expand_filename(d);
     tor_free(options->DataDirectory);
-    options->DataDirectory = tor_strdup(buf);
+    options->DataDirectory = fn;
   }
   return options->DataDirectory;
 }