aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/daemon.c14
-rw-r--r--src/daemon.h5
2 files changed, 7 insertions, 12 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 43d16bc9b..5ae79e050 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -85,23 +85,13 @@ daemonize_kill(void)
exit(EXIT_SUCCESS);
}
-#endif
-
void
daemonize_close_stdin(void)
{
- int fd = open("/dev/null", O_RDONLY);
-
- if (fd < 0)
- close(STDIN_FILENO);
- else if (fd != STDIN_FILENO) {
- dup2(fd, STDIN_FILENO);
- close(fd);
- }
+ close(STDIN_FILENO);
+ open("/dev/null", O_RDONLY);
}
-#ifndef WIN32
-
void
daemonize_set_user(void)
{
diff --git a/src/daemon.h b/src/daemon.h
index 1332eaf48..a29945607 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -56,8 +56,13 @@ daemonize_kill(void)
/**
* Close stdin (fd 0) and re-open it as /dev/null.
*/
+#ifndef WIN32
void
daemonize_close_stdin(void);
+#else
+static inline void
+daemonize_close_stdin(void) {}
+#endif
/**
* Change to the configured Unix user.