summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-12 02:18:08 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-12 02:18:08 +0000
commitd2708ba2fb137a98a5aa96553133290f11dff770 (patch)
treeb72d6fa7cbb1282611633c498fe9c4c95b7bf172 /src
parentfixed kamikaze package makefile (diff)
improved daemonizing
Diffstat (limited to 'src')
-rw-r--r--src/daemon.h22
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);