lib/util/run_cmd: prevent zombies in samba_runcmd_send on timeout
authorRalph Boehme <slow@samba.org>
Fri, 29 Sep 2017 10:45:24 +0000 (12:45 +0200)
committerRalph Boehme <slow@samba.org>
Sat, 30 Sep 2017 06:01:24 +0000 (08:01 +0200)
Ensure the state desctructor calls tfork_destroy to reap the waiter and
worker processes. Otherwise we leave the waiter process as a zombie
behind us as we never call waitpid on it in case of a timeout
or talloc_free() from the caller.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13062

Pair-programmed-with: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
lib/util/util_runcmd.c

index 6077fddde56274d707403da507f3d73f062eb826..ef3402ad33fccd305393a16b5cb1b4355ccb4ede 100644 (file)
 
 static int samba_runcmd_state_destructor(struct samba_runcmd_state *state)
 {
-       if (state->pid > 0) {
-               kill(state->pid, SIGKILL);
-               waitpid(state->pid, NULL, 0);
-               state->pid = -1;
+       if (state->tfork != NULL) {
+               tfork_destroy(&state->tfork);
        }
+       state->pid = -1;
 
        if (state->fd_stdin != -1) {
                close(state->fd_stdin);
@@ -275,6 +274,7 @@ static void samba_runcmd_io_handler(struct tevent_context *ev,
                        tevent_req_error(req, errno);
                        return;
                }
+               state->pid = -1;
                TALLOC_FREE(fde);
 
                if (WIFEXITED(status)) {