aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-04-06 19:07:38 +0000
committerRoger Dingledine <arma@torproject.org>2005-04-06 19:07:38 +0000
commit652dde72f1beed1fb83d137314f47aff15b01036 (patch)
treef414cd4a41a69d367f68f4c4fdaeae054b5e2aad /src/common
parent8596947ee220a4ff342cfd72d86cabbf8b6966d8 (diff)
downloadtor-652dde72f1beed1fb83d137314f47aff15b01036.tar
tor-652dde72f1beed1fb83d137314f47aff15b01036.tar.gz
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. svn:r4033
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c26
-rw-r--r--src/common/util.h4
2 files changed, 15 insertions, 15 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 09409e701..943f912b4 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1334,7 +1334,7 @@ static int daemon_filedes[2];
* 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 @@ void start_daemon(const char *desired_cwd)
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 @@ void start_daemon(const char *desired_cwd)
* 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 @@ void finish_daemon(void)
}
#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>.
diff --git a/src/common/util.h b/src/common/util.h
index 6f23e219a..b3262d87a 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -132,8 +132,8 @@ int tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len);
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