mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-12 15:17:14 +03:00
close std-filehandles when daemonize
This commit is contained in:
parent
18a9a882f5
commit
d6bb000115
@ -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
|
||||
*/
|
||||
|
||||
|
10
sslh-main.c
10
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user