mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
Build fix for gcc.
This commit is contained in:
parent
69c30c264a
commit
09001efd18
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user