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 */ /* create new process */
pid = fork ( ); pid = fork();
if (pid == -1) if (pid == -1)
return -1; return -1;
@ -285,8 +285,9 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
} }
} }
if (triple_fork) {
/* Fork once again */ /* Fork once again */
pid = fork ( ); pid = fork();
if (pid == -1) { if (pid == -1) {
if (!exit_parent) { if (!exit_parent) {
close(pipes[1]); close(pipes[1]);
@ -298,6 +299,7 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
else if (pid != 0) { else if (pid != 0) {
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
}
setenv("_", "/bin/true", 1); setenv("_", "/bin/true", 1);