diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/daemon.h b/src/daemon.h index 8959c7e..f3ed638 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -128,11 +128,31 @@ void daemonize() pid_t pid; pid = fork(); + if(pid < 0) { + log_printf(WARNING, "daemonizing failed at fork(): %m, exitting"); + exit(-1); + } if(pid) exit(0); - setsid(); + + umask(0); + + if(setsid() < 0) { + log_printf(WARNING, "daemonizing failed at setsid(): %m, exitting"); + exit(-1); + } + pid = fork(); + if(pid < 0) { + log_printf(WARNING, "daemonizing failed at fork(): %m, exitting"); + exit(-1); + } if(pid) exit(0); + if ((chdir("/")) < 0) { + log_printf(WARNING, "daemonizing failed at chdir(): %m, exitting"); + exit(-1); + } + int fd; for (fd=0;fd<=2;fd++) // close all file descriptors close(fd); |