From 8ff6e4897d3271d688c3f491e2c1baf97f088545 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 26 Jun 2009 22:12:20 +0000 Subject: After logging (if enabled) is switched to file, there is no reason to keep stdin/stdout/stderr active, so dup them to /dev/null. --- usr.bin/tmux/server.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'usr.bin/tmux/server.c') diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 54b0e5ac803..a1f908b7ac1 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.4 2009/06/25 22:09:20 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.5 2009/06/26 22:12:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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); -- cgit v1.2.3