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;
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;
}