For PID=1 do just one fork

This commit is contained in:
Oleksii Shevchuk 2018-02-09 16:08:57 +02:00
parent d9208d792d
commit 0786e5e8a7
1 changed files with 13 additions and 11 deletions

View File

@ -268,7 +268,7 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
}
/* create new process */
pid = fork ( );
pid = fork();
if (pid == -1)
return -1;
@ -285,18 +285,20 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
}
}
/* Fork once again */
pid = fork ( );
if (pid == -1) {
if (!exit_parent) {
close(pipes[1]);
if (triple_fork) {
/* Fork once again */
pid = fork();
if (pid == -1) {
if (!exit_parent) {
close(pipes[1]);
}
return -1;
}
return -1;
}
else if (pid != 0) {
exit (EXIT_SUCCESS);
else if (pid != 0) {
exit (EXIT_SUCCESS);
}
}
setenv("_", "/bin/true", 1);