winbindd: allocate winbindd child state on heap
authorDavid Disseldorp <ddiss@samba.org>
Thu, 18 Apr 2013 15:12:15 +0000 (17:12 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Thu, 18 Apr 2013 15:12:15 +0000 (17:12 +0200)
Allows the structure to be passed to the tevent_done callback.

source3/winbindd/winbindd_dual.c

index ea7b99ff81a6d986ed8539c395b224196bf1f3b2..bb9314c3f4d2180ccdf47ce1f4ea67c7bd837670 100644 (file)
@@ -1398,7 +1398,8 @@ static void domain_child_loop_done(struct tevent_req *req);
 static bool fork_domain_child(struct winbindd_child *child)
 {
        int fdpair[2];
-       struct winbindd_cli_state state;
+       pid_t parent_pid;
+       struct winbindd_cli_state *state;
        struct winbindd_domain *primary_domain = NULL;
        NTSTATUS status;
        ssize_t nwritten;
@@ -1417,9 +1418,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                return False;
        }
 
-       ZERO_STRUCT(state);
-       state.pid = getpid();
-
+       parent_pid = getpid();
        child->pid = fork();
 
        if (child->pid == -1) {
@@ -1459,12 +1458,9 @@ static bool fork_domain_child(struct winbindd_child *child)
 
        DEBUG(10, ("Child process %d\n", (int)getpid()));
 
-       state.sock = fdpair[0];
-       close(fdpair[1]);
-
        status = winbindd_reinit_after_fork(child, child->logfilename);
 
-       nwritten = sys_write(state.sock, &status, sizeof(status));
+       nwritten = sys_write(fdpair[0], &status, sizeof(status));
        if (nwritten != sizeof(status)) {
                DEBUG(1, ("fork_domain_child: Could not write status: "
                          "nwritten=%d, error=%s\n", (int)nwritten,
@@ -1476,6 +1472,15 @@ static bool fork_domain_child(struct winbindd_child *child)
                          nt_errstr(status)));
                _exit(0);
        }
+
+       state = talloc_zero(NULL, struct winbindd_cli_state);
+       if (state == NULL) {
+               _exit(0);
+       }
+       state->pid = parent_pid;
+       state->sock = fdpair[0];
+       close(fdpair[1]);
+
        ev = winbind_event_context();
 
        /* Handle online/offline messages. */
@@ -1596,7 +1601,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                        _exit(1);
                }
 
-               pfds->fd = state.sock;
+               pfds->fd = state->sock;
                pfds->events = POLLIN|POLLHUP;
                num_pfds = 1;
 
@@ -1645,23 +1650,23 @@ static bool fork_domain_child(struct winbindd_child *child)
                }
 
                /* alloc and fetch a request from the main daemon */
-               status = child_read_request(mem_ctx, state.sock,
-                                           &state.request);
+               status = child_read_request(mem_ctx, state->sock,
+                                           &state->request);
                if (!NT_STATUS_IS_OK(status)) {
                        /* we lost contact with our parent */
                        _exit(0);
                }
 
-               DEBUG(4,("child daemon request %d\n", (int)state.request->cmd));
+               DEBUG(4,("child daemon request %d\n", (int)state->request->cmd));
 
-               state.response = talloc_zero(mem_ctx, struct winbindd_response);
-               if (state.response == NULL) {
+               state->response = talloc_zero(mem_ctx, struct winbindd_response);
+               if (state->response == NULL) {
                        _exit(1);
                }
 
-               state.mem_ctx = mem_ctx;
+               state->mem_ctx = mem_ctx;
                req = child_process_request_send(mem_ctx, ev, child->domain,
-                                                child->table, &state);
+                                                child->table, state);
                if (req == NULL) {
                        DEBUG(0, ("failed to dispatch child request\n"));
                        TALLOC_FREE(mem_ctx);
@@ -1669,7 +1674,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                }
                tevent_req_set_callback(req,
                                        domain_child_loop_done,
-                                       &state);
+                                       state);
 
        }
 }