Build fix for gcc.

This commit is contained in:
Gunnar Beutner 2012-04-23 08:42:24 +02:00
parent 69c30c264a
commit 09001efd18

View File

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