[or-cvs] bugfix: chdir to your datadirectory at the *end* of the

Roger Dingledine arma at seul.org
Wed Apr 6 19:07:38 UTC 2005


Update of /home2/or/cvsroot/tor/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/common

Modified Files:
	util.c util.h 
Log Message:
bugfix: chdir to your datadirectory at the *end* of the
daemonize process, not the beginning. this was a problem
because the first time you run tor, if your datadir isn't
there, and you have runasdaemon set to 1, it will try to
chdir to it before it tries to create it. oops.


Index: util.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.207
retrieving revision 1.208
diff -u -d -r1.207 -r1.208
--- util.c	1 Apr 2005 20:15:54 -0000	1.207
+++ util.c	6 Apr 2005 19:07:35 -0000	1.208
@@ -1334,7 +1334,7 @@
  * until finish_daemon is called.  (Note: it's safe to call this more
  * than once: calls after the first are ignored.)
  */
-void start_daemon(const char *desired_cwd)
+void start_daemon(void)
 {
   pid_t pid;
 
@@ -1342,14 +1342,6 @@
     return;
   start_daemon_called = 1;
 
-  if (!desired_cwd)
-    desired_cwd = "/";
-   /* Don't hold the wrong FS mounted */
-  if (chdir(desired_cwd) < 0) {
-    log_fn(LOG_ERR,"chdir to %s failed. Exiting.",desired_cwd);
-    exit(1);
-  }
-
   pipe(daemon_filedes);
   pid = fork();
   if (pid < 0) {
@@ -1393,16 +1385,24 @@
  * calls after the first are ignored.  Calls start_daemon first if it hasn't
  * been called already.)
  */
-void finish_daemon(void)
+void finish_daemon(const char *desired_cwd)
 {
   int nullfd;
   char c = '.';
   if (finish_daemon_called)
     return;
   if (!start_daemon_called)
-    start_daemon(NULL);
+    start_daemon();
   finish_daemon_called = 1;
 
+  if (!desired_cwd)
+    desired_cwd = "/";
+   /* Don't hold the wrong FS mounted */
+  if (chdir(desired_cwd) < 0) {
+    log_fn(LOG_ERR,"chdir to %s failed. Exiting.",desired_cwd);
+    exit(1);
+  }
+
   nullfd = open("/dev/null",
                 O_CREAT | O_RDWR | O_APPEND);
   if (nullfd < 0) {
@@ -1424,8 +1424,8 @@
 }
 #else
 /* defined(MS_WINDOWS) */
-void start_daemon(const char *cp) {}
-void finish_daemon(void) {}
+void start_daemon(void) {}
+void finish_daemon(const char *cp) {}
 #endif
 
 /** Write the current process ID, followed by NL, into <b>filename</b>.

Index: util.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -d -r1.131 -r1.132
--- util.h	1 Apr 2005 20:15:54 -0000	1.131
+++ util.h	6 Apr 2005 19:07:35 -0000	1.132
@@ -132,8 +132,8 @@
 int is_plausible_address(const char *name);
 
 /* Process helpers */
-void start_daemon(const char *desired_cwd);
-void finish_daemon(void);
+void start_daemon(void);
+void finish_daemon(const char *desired_cwd);
 void write_pidfile(char *filename);
 
 #endif



More information about the tor-commits mailing list