aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/process/daemon.c10
-rw-r--r--src/lib/process/daemon.h2
2 files changed, 7 insertions, 5 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;
}
}
diff --git a/src/lib/process/daemon.h b/src/lib/process/daemon.h
index 08cab17e12..c3b78029af 100644
--- a/src/lib/process/daemon.h
+++ b/src/lib/process/daemon.h
@@ -11,7 +11,7 @@
#ifndef TOR_DAEMON_H
#define TOR_DAEMON_H
-void start_daemon(void);
+int start_daemon(void);
int finish_daemon(const char *desired_cwd);
#endif