diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-06-26 22:13:57 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-06-26 22:13:57 +0000 |
commit | 6ce734cec0646bdff5af28dd71d1a0620d9ab9f8 (patch) | |
tree | 82292b06f22fa9aac0e81a79c548d9a3389371a1 | |
parent | 826add53f19fabb474babc317b4f8f9a322dcb95 (diff) | |
download | rtmux-6ce734cec0646bdff5af28dd71d1a0620d9ab9f8.tar.gz rtmux-6ce734cec0646bdff5af28dd71d1a0620d9ab9f8.tar.bz2 rtmux-6ce734cec0646bdff5af28dd71d1a0620d9ab9f8.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.
-rw-r--r-- | server.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -131,7 +131,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; #ifdef HAVE_SETPROCTITLE char rpathbuf[MAXPATHLEN]; @@ -178,6 +178,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); |