From 957ad36d258c25e8fe27daddd4df123221b377a3 Mon Sep 17 00:00:00 2001 From: Vassili Tchersky Date: Thu, 10 Sep 2020 12:48:33 +0300 Subject: [PATCH] Handle potential fork error --- god.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/god.c b/god.c index e518324..0a80874 100644 --- a/god.c +++ b/god.c @@ -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); @@ -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);