aboutsummaryrefslogtreecommitdiffstats
path: root/src/satd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/satd.c')
-rw-r--r--src/satd.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/satd.c b/src/satd.c
index ed5d07a..1bfb829 100644
--- a/src/satd.c
+++ b/src/satd.c
@@ -196,9 +196,6 @@ main(int argc, char *argv[])
else if ((path = getenv("SATD_SOCKET_PATH")))
have_socket = S_ISSOCK(attr.st_mode);
- /* Daemonise. */
- t (foreground ? 0 : daemonise("satd", have_socket ? DAEMONISE_KEEP_STDIN : 0));
-
/* Get or create socket. */
if (have_socket) {
if (strlen(path) >= sizeof(address.sun_path))
@@ -232,6 +229,13 @@ main(int argc, char *argv[])
t (listen(sock, SATD_BACKLOG));
#endif
+ /* Daemonise. */
+ if (!foreground) {
+ int flags = have_socket ? DAEMONISE_KEEP_STDIN : 0;
+ flags |= DAEMONISE_KEEP_FDS;
+ t (daemonise("satd", flags, sock, -1));
+ }
+
close(sock);
unlink(address.sun_path);
undaemonise();