From: Michael Tremer Date: Tue, 21 Oct 2025 07:26:01 +0000 (+0000) Subject: command: Defer cleaning up the command to avoid zombies X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43e45d0b2ef880426bf33a6c65e9666527857a15;p=telemetry.git command: Defer cleaning up the command to avoid zombies Signed-off-by: Michael Tremer --- diff --git a/src/daemon/command.c b/src/daemon/command.c index d5d45cb..6d8a145 100644 --- a/src/daemon/command.c +++ b/src/daemon/command.c @@ -299,6 +299,22 @@ static int td_command_log_stderr(td_ctx* ctx, td_file* file, return 0; } +/* + This function simply drops a reference to the command. + + It is being called after the command has exited, but cannot be called in the + same iteration because we will cleanup the command and prevent the event loop + from reaping the process. Therefore we will be left with lots of zombies. +*/ +static int td_command_cleanup(sd_event_source* source, void* data) { + td_command* self = data; + + // Drop the reference + td_command_unref(self); + + return 0; +} + static int td_command_exited(sd_event_source* source, const siginfo_t* si, void* data) { td_command* self = data; td_file* stdout = NULL; @@ -384,7 +400,7 @@ ERROR: td_file_unref(stdout); // Drop the extra reference - td_command_unref(self); + sd_event_add_defer(self->loop, NULL, td_command_cleanup, self); return r; }