Skip to content

Commit

Permalink
Merge pull request #16 from spreadspace/topic/daemonize-needs-setsid
Browse files Browse the repository at this point in the history
fix daemonize
  • Loading branch information
fiorix authored Aug 5, 2024
2 parents b37d4c4 + 164e7a1 commit 1959731
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions god.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ int main(int argc, char **argv) {

// Daemonize.
pid_t pid = fork();
if (pid) {
if (pid > 0) {
waitpid(pid, NULL, 0);
} else if (!pid) {
if ((pid = fork())) {
if(setsid() < 0) {
perror("setsid");
exit(1);
}
if ((pid = fork()) > 0) {
exit(0);
} else if (!pid) {
daemon_main(optind, argv);
Expand Down Expand Up @@ -218,7 +222,7 @@ void daemon_main(int optind, char **argv) {
}
signal(SIGHUP, sighup);
pipe(logfd);
if ((childpid = fork())) {
if ((childpid = fork()) > 0) {
close(0);
close(1);
close(2);
Expand Down

0 comments on commit 1959731

Please sign in to comment.