summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c26
-rw-r--r--src/common/util.h4
-rw-r--r--src/or/config.c4
3 files changed, 17 insertions, 17 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 09409e7016..943f912b47 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 6f23e219a6..b3262d87a3 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
diff --git a/src/or/config.c b/src/or/config.c
index 97039fa96a..1d03146cf1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -266,7 +266,7 @@ options_act(void) {
* It let us have the parent process stick around until we were sure Tor
* was started. Should we make start_daemon get called earlier? -NM */
if (options->RunAsDaemon) {
- start_daemon(options->DataDirectory);
+ start_daemon();
}
if (!libevent_initialized) {
configure_libevent_logging();
@@ -346,7 +346,7 @@ options_act(void) {
/* Finish backgrounding the process */
if (options->RunAsDaemon) {
/* We may be calling this for the n'th time (on SIGHUP), but it's safe. */
- finish_daemon();
+ finish_daemon(options->DataDirectory);
}
/* Write our pid to the pid file. If we do not have write permissions we