Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle potential fork error #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions god.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ 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 ((pid = fork()) > 0) {
exit(0);
} else if (!pid) {
daemon_main(optind, argv);
Expand Down Expand Up @@ -218,7 +218,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