]> git.ipfire.org Git - telemetry.git/commitdiff
command: Defer cleaning up the command to avoid zombies
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 07:26:01 +0000 (07:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 07:26:01 +0000 (07:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/command.c

index d5d45cbd54dbfc9953e5ce0653e0297c1130a389..6d8a145b60bb7021c5c9ebb62c9b848fc69f1670 100644 (file)
@@ -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;
 }