diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-06-26 22:12:19 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-06-26 22:12:19 +0000 |
commit | 46f80d01ff2c0e611b46acf309df45c4a2c21eb5 (patch) | |
tree | a9632ece90cb835de645fc3dcb8a63505b13b9d4 /server.c | |
parent | b11b1dd1c0666a98f167ad56370b920c7769a85b (diff) | |
download | rtmux-46f80d01ff2c0e611b46acf309df45c4a2c21eb5.tar.gz rtmux-46f80d01ff2c0e611b46acf309df45c4a2c21eb5.tar.bz2 rtmux-46f80d01ff2c0e611b46acf309df45c4a2c21eb5.zip |
After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -25,6 +25,7 @@ #include <errno.h> #include <fcntl.h> +#include <paths.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -131,7 +132,7 @@ server_client_index(struct client *c) int server_start(char *path) { - int pair[2], srv_fd; + int pair[2], srv_fd, null_fd; char *cause; char rpathbuf[MAXPATHLEN]; @@ -176,6 +177,18 @@ server_start(char *path) } logfile("server"); + /* + * Close stdin/stdout/stderr. Can't let daemon() do this as they are + * needed until now to print configuration file errors. + */ + if ((null_fd = open(_PATH_DEVNULL, O_RDWR)) != -1) { + dup2(null_fd, STDIN_FILENO); + dup2(null_fd, STDOUT_FILENO); + dup2(null_fd, STDERR_FILENO); + if (null_fd > 2) + close(null_fd); + } + log_debug("server started, pid %ld", (long) getpid()); log_debug("socket path %s", socket_path); |