close std-filehandles when daemonize

This commit is contained in:
ftasnetamot authored and Yves Rutschle committed 2024-09-08 16:56:50 +02:00
1 parent 18a9a882f5
commit d6bb000115
2 files changed
+11 -1

No files matched your search

+1 -1
View File
@@ -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
View File
@@ -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) {