Skip to content

Commit

Permalink
SPAWN SERVER: close all open fds on callback (netdata#18764)
Browse files Browse the repository at this point in the history
close all open fds on callback
  • Loading branch information
ktsaou authored Oct 11, 2024
1 parent 6c3e9b1 commit e99060f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/libnetdata/spawn_server/spawn_server_nofork.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static void spawn_server_run_child(SPAWN_SERVER *server, SPAWN_REQUEST *rq) {
if(server->pipe[0] != -1) { close(server->pipe[0]); server->pipe[0] = -1; }
if(server->pipe[1] != -1) { close(server->pipe[1]); server->pipe[1] = -1; }

// close all open file descriptors of the parent, but keep ours
os_close_all_non_std_open_fds_except(rq->fds, 4, 0);

// set the process name
os_setproctitle("spawn-child", server->argc, server->argv);

Expand Down Expand Up @@ -351,8 +354,6 @@ static bool spawn_server_run_callback(SPAWN_SERVER *server __maybe_unused, SPAWN
}

pid_t pid = fork();
gettid_uncached(); // make sure the logger logs valid pids

if (pid < 0) {
// fork failed

Expand All @@ -362,6 +363,7 @@ static bool spawn_server_run_callback(SPAWN_SERVER *server __maybe_unused, SPAWN
else if (pid == 0) {
// the child

gettid_uncached(); // make sure the logger logs valid pids
spawn_server_run_child(server, rq);
exit(63);
}
Expand Down Expand Up @@ -1068,6 +1070,7 @@ SPAWN_SERVER* spawn_server_create(SPAWN_SERVER_OPTIONS options, const char *name
pid_t pid = fork();
if (pid == 0) {
// the child - the spawn server
gettid_uncached(); // make sure the logger logs valid pids

{
char buf[15];
Expand Down

0 comments on commit e99060f

Please sign in to comment.