]> git.ozlabs.org Git - ccan/blobdiff - ccan/daemonize/daemonize.c
endian: fix compilation with musl libc.
[ccan] / ccan / daemonize / daemonize.c
index ff12bfce3f7d15dfcab1053f7a673cae23963125..bd32ecbbaeebc866426eb212ca3811264e060d21 100644 (file)
@@ -1,3 +1,4 @@
+/* Licensed under BSD-MIT - see LICENSE file for details */
 #include <ccan/daemonize/daemonize.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -14,8 +15,9 @@ bool daemonize(void)
        /* Separate from our parent via fork, so init inherits us. */
        if ((pid = fork()) < 0)
                return false;
+       /* use _exit() to avoid triggering atexit() processing */
        if (pid != 0)
-               exit(0);
+               _exit(0);
 
        /* Don't hold files open. */
        close(STDIN_FILENO);
@@ -31,7 +33,8 @@ bool daemonize(void)
        close(0);
 
        /* Session leader so ^C doesn't whack us. */
-       setsid();
+       if (setsid() == (pid_t)-1)
+               return false;
        /* Move off any mount points we might be in. */
        if (chdir("/") != 0)
                return false;