]> granicus.if.org Git - icinga2/commitdiff
Build fix for gcc.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 06:42:24 +0000 (08:42 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 06:42:24 +0000 (08:42 +0200)
base/utility.cpp

index 167f703105c9362d0caf4b62aaed46e6f32719e0..f1bd7e970ac2b23422503b9e4619f750b755e1f3 100644 (file)
@@ -10,39 +10,33 @@ using namespace icinga;
 void Utility::Daemonize(void) {
 #ifndef _WIN32
        pid_t pid;
-       pid_t sid;
        int fd;
 
        pid = fork();
-       if (pid == -1) {
-               return false;
-       }
+       if (pid < 0)
+               throw PosixException("fork failed", errno);
 
        if (pid)
                exit(0);
 
        fd = open("/dev/null", O_RDWR);
-       if (fd) {
-               if (fd != 0) {
-                       dup2(fd, 0);
-               }
-
-               if (fd != 1) {
-                       dup2(fd, 1);
-               }
-
-               if (fd != 2) {
-                       dup2(fd, 2);
-               }
-
-               if (fd > 2) {
-                       close(fd);
-               }
-       }
-
-       sid = setsid();
-       if (sid == -1) {
-               return false;
-       }
+
+       if (fd < 0)
+               throw PosixException("open failed", errno);
+
+       if (fd != 0)
+               dup2(fd, 0);
+
+       if (fd != 1)
+               dup2(fd, 1);
+
+       if (fd != 2)
+               dup2(fd, 2);
+
+       if (fd > 2)
+               close(fd);
+
+       if (setsid() < 0)
+               throw PosixException("setsid failed", errno);
 #endif
 }