runcmd: use set_close_on_exec()
authorAndrew Tridgell <tridge@samba.org>
Wed, 30 Nov 2011 04:18:29 +0000 (15:18 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 22 Dec 2011 13:00:06 +0000 (14:00 +0100)
this prevents a fd leak to child processes

Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Thu Dec 22 14:00:06 CET 2011 on sn-devel-104

lib/util/util_runcmd.c

index 8a475ef301d01dad1feb54c4bb6c518e3b00d106..cc274c21d54c3a76423818a59ed66a1a2f954709 100644 (file)
@@ -135,6 +135,10 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx,
                set_blocking(state->fd_stderr, false);
                set_blocking(state->fd_stdin,  false);
 
+               smb_set_close_on_exec(state->fd_stdin);
+               smb_set_close_on_exec(state->fd_stdout);
+               smb_set_close_on_exec(state->fd_stderr);
+
                talloc_set_destructor(state, samba_runcmd_state_destructor);
 
                state->fde_stdout = tevent_add_fd(ev, state,
@@ -197,6 +201,10 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx,
        dup2(p1[1], 1);
        dup2(p2[1], 2);
 
+       close(p1[1]);
+       close(p2[1]);
+       close(p3[0]);
+
        argv = str_list_copy(state, discard_const_p(const char *, argv0));
        if (!argv) {
                fprintf(stderr, "Out of memory in child\n");