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;
return False;
}
- ZERO_STRUCT(state);
- state.pid = getpid();
-
+ parent_pid = getpid();
child->pid = fork();
if (child->pid == -1) {
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,
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. */
_exit(1);
}
- pfds->fd = state.sock;
+ pfds->fd = state->sock;
pfds->events = POLLIN|POLLHUP;
num_pfds = 1;
}
/* 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);
}
tevent_req_set_callback(req,
domain_child_loop_done,
- &state);
+ state);
}
}