diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-01-16 16:19:28 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-01-16 16:19:28 +0000 |
commit | fc073b9af90ff44efcbb318633d026e754f86907 (patch) | |
tree | c0405794f4a429e2bf8165cd5c55abf156638f72 | |
parent | e9799abfdd2520e3adbd5c3a1d27a9e466361598 (diff) |
Redirect stdin, stdout, stderr to /dev/null for daemon
-rw-r--r-- | sdpd/main.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sdpd/main.c b/sdpd/main.c index dd725c81..685ffa8b 100644 --- a/sdpd/main.c +++ b/sdpd/main.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <errno.h> +#include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> @@ -301,8 +302,16 @@ static int become_daemon(void) return 0; setsid(); } - for (fd = 0; fd < 3; fd++) - close(fd); + + fd = open("/dev/null", O_RDWR); + if (fd != -1) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + + if (fd > STDERR_FILENO) + close(fd); + } chdir("/"); return 1; |