mirror of https://github.com/Icinga/icinga2.git
Build fix for gcc.
This commit is contained in:
parent
69c30c264a
commit
09001efd18
|
@ -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 < 0)
|
||||
throw PosixException("open failed", errno);
|
||||
|
||||
if (fd != 2) {
|
||||
dup2(fd, 2);
|
||||
}
|
||||
if (fd != 0)
|
||||
dup2(fd, 0);
|
||||
|
||||
if (fd > 2) {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
if (fd != 1)
|
||||
dup2(fd, 1);
|
||||
|
||||
sid = setsid();
|
||||
if (sid == -1) {
|
||||
return false;
|
||||
}
|
||||
if (fd != 2)
|
||||
dup2(fd, 2);
|
||||
|
||||
if (fd > 2)
|
||||
close(fd);
|
||||
|
||||
if (setsid() < 0)
|
||||
throw PosixException("setsid failed", errno);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue