aboutsummaryrefslogtreecommitdiff
path: root/src/lib/process/daemon.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-08-08 17:32:26 -0400
committerNick Mathewson <nickm@torproject.org>2018-08-08 17:32:26 -0400
commita57c27a1c749add88b088f570838373687a0c6fd (patch)
treebf14a87832ae51322b2c039b0c2174f4d67b7747 /src/lib/process/daemon.c
parent622a2c6bee19af3bab0e84702a36ff2df39db7e7 (diff)
downloadtor-a57c27a1c749add88b088f570838373687a0c6fd.tar.gz
tor-a57c27a1c749add88b088f570838373687a0c6fd.zip
Call crypto_postfork on start_daemon() instead.
Diffstat (limited to 'src/lib/process/daemon.c')
-rw-r--r--src/lib/process/daemon.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/process/daemon.c b/src/lib/process/daemon.c
index 4836b3951c..3fc2241045 100644
--- a/src/lib/process/daemon.c
+++ b/src/lib/process/daemon.c
@@ -41,15 +41,16 @@ static int daemon_filedes[2];
/** Start putting the process into daemon mode: fork and drop all resources
* except standard fds. The parent process never returns, but stays around
* until finish_daemon is called. (Note: it's safe to call this more
- * than once: calls after the first are ignored.)
+ * than once: calls after the first are ignored.) Return true if we actually
+ * forked and this is the child; false otherwise.
*/
-void
+int
start_daemon(void)
{
pid_t pid;
if (start_daemon_called)
- return;
+ return 0;
start_daemon_called = 1;
if (pipe(daemon_filedes)) {
@@ -80,6 +81,7 @@ start_daemon(void)
exit(0); // exit ok: during daemonize, daemonizing.
else
exit(1); /* child reported error. exit ok: daemonize failed. */
+ return 0; // LCOV_EXCL_LINE unreachable
} else { /* Child */
close(daemon_filedes[0]); /* we only write */
@@ -95,7 +97,7 @@ start_daemon(void)
}
set_main_thread(); /* We are now the main thread. */
- return;
+ return 1;
}
}