- pfds = TALLOC_ZERO_P(talloc_tos(), struct pollfd);
- if (pfds == NULL) {
- DEBUG(1, ("talloc failed\n"));
- _exit(1);
- }
-
- pfds->fd = state.sock;
- pfds->events = POLLIN|POLLHUP;
- num_pfds = 1;
-
- timeout = INT_MAX;
-
- if (!event_add_to_poll_args(
- winbind_event_context(), talloc_tos(),
- &pfds, &num_pfds, &timeout)) {
- DEBUG(1, ("event_add_to_poll_args failed\n"));
- _exit(1);
- }
- tp = get_timed_events_timeout(winbind_event_context(), &t);
- if (tp) {
- DEBUG(11,("select will use timeout of %u.%u seconds\n",
- (unsigned int)tp->tv_sec, (unsigned int)tp->tv_usec ));
- }
-
- ret = sys_poll(pfds, num_pfds, timeout);
-
- if (run_events_poll(winbind_event_context(), ret,
- pfds, num_pfds)) {
- /* We got a signal - continue. */
- TALLOC_FREE(frame);
- continue;
- }
-
- TALLOC_FREE(pfds);
-
- if (ret == 0) {
- DEBUG(11,("nothing is ready yet, continue\n"));
- TALLOC_FREE(frame);
- continue;
- }
-
- if (ret == -1 && errno == EINTR) {
- /* We got a signal - continue. */
- TALLOC_FREE(frame);
- continue;
- }
-
- if (ret == -1 && errno != EINTR) {
- DEBUG(0,("poll error occured\n"));
- TALLOC_FREE(frame);
- perror("poll");
- _exit(1);
- }
-
- /* fetch a request from the main daemon */
- status = child_read_request(&state);
-
- 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));
-
- ZERO_STRUCTP(state.response);
- state.request->null_term = '\0';
- state.mem_ctx = frame;
- child_process_request(child, &state);
-
- DEBUG(4, ("Finished processing child request %d\n",
- (int)state.request->cmd));
-
- SAFE_FREE(state.request->extra_data.data);
-
- iov[0].iov_base = (void *)state.response;
- iov[0].iov_len = sizeof(struct winbindd_response);
- iov_count = 1;
-
- if (state.response->length > sizeof(struct winbindd_response)) {
- iov[1].iov_base =
- (void *)state.response->extra_data.data;
- iov[1].iov_len = state.response->length-iov[0].iov_len;
- iov_count = 2;
- }
-
- DEBUG(10, ("Writing %d bytes to parent\n",
- (int)state.response->length));
-
- if (write_data_iov(state.sock, iov, iov_count) !=
- state.response->length) {
- DEBUG(0, ("Could not write result\n"));
- exit(1);
- }