diff --git a/sslh-fork.c b/sslh-fork.c index 40a1b5a..dfe39a4 100644 --- a/sslh-fork.c +++ b/sslh-fork.c @@ -272,7 +272,7 @@ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen) wait(NULL); } -/* The actual main is in common.c: it's the same for both version of +/* The actual main() is in sslh_main.c: it's the same for all versions of * the server */ diff --git a/sslh-main.c b/sslh-main.c index e4eb490..5c6f9c4 100644 --- a/sslh-main.c +++ b/sslh-main.c @@ -287,6 +287,16 @@ int main(int argc, char *argv[], char* envp[]) if (!cfg.foreground) { if (fork() > 0) exit(0); /* Detach */ + // close stdin, stderr, stdout + int newfd; + if (newfd = open("/dev/null", O_RDWR)) { + dup2 (newfd, STDIN_FILENO); + dup2 (newfd, STDOUT_FILENO); + dup2 (newfd, STDERR_FILENO); + close(newfd); + } else { + print_message(msg_config, "Error closing standard filehandles for background daemon\n"); + } /* New session -- become group leader */ if (getuid() == 0) {