[or-cvs] Normalize DataDirectory in options_validate, making SIGHUP ...

Nick Mathewson nickm at seul.org
Tue Nov 9 05:26:52 UTC 2004


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

Modified Files:
	config.c 
Log Message:
Normalize DataDirectory in options_validate, making SIGHUP survivable.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.220
retrieving revision 1.221
diff -u -d -r1.220 -r1.221
--- config.c	9 Nov 2004 05:18:15 -0000	1.220
+++ config.c	9 Nov 2004 05:26:49 -0000	1.221
@@ -958,6 +958,11 @@
     result = -1;
   }
 
+  if (validate_data_directory(options)<0) {
+    log(LOG_WARN, "Invalid DataDirectory");
+    result = -1;
+  }
+
   if (options->Nickname == NULL) {
     if (server_mode(options)) {
       if (!(options->Nickname = get_default_nickname()))
@@ -1205,7 +1210,7 @@
        (!new_val->DataDirectory ||
         strcmp(old->DataDirectory,new_val->DataDirectory)!=0)) ||
       (!old->DataDirectory && new_val->DataDirectory)) {
-    log_fn(LOG_WARN,"During reload, changing DataDirectory is not allowed. Failing.");
+    log_fn(LOG_WARN,"During reload, changing DataDirectory (%s->%s) is not allowed. Failing.", old->DataDirectory, new_val->DataDirectory);
     return -1;
   }
 
@@ -1818,12 +1823,14 @@
 const char *
 get_data_directory(void)
 {
+  return get_options()->DataDirectory;
+}
+
+static int
+validate_data_directory(or_options_t *options) {
   const char *d;
-  or_options_t *options = get_options();
 
-  if (options->DataDirectory) {
-    d = options->DataDirectory;
-  } else {
+  if (!options->DataDirectory) {
 #ifdef MS_WINDOWS
     char *p;
     p = tor_malloc(MAX_PATH);
@@ -1832,19 +1839,20 @@
     return p;
 #else
     d = "~/.tor";
-#endif
   }
+#endif
 
-  if (d && strncmp(d,"~/",2) == 0) {
-    char *fn = expand_filename(d);
-    if (!fn) {
-      log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.", d);
-      exit(1);
-    }
-    tor_free(options->DataDirectory);
-    options->DataDirectory = fn;
-  }
-  return options->DataDirectory;
+ if (d && strncmp(d,"~/",2) == 0) {
+   char *fn = expand_filename(d);
+   if (!fn) {
+     log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.", d);
+     exit(1);
+   }
+   tor_free(options->DataDirectory);
+   options->DataDirectory = fn;
+ }
+
+ return 0;
 }
 
 /*



More information about the tor-commits mailing list