- FD_ZERO(&r_fds);
- FD_ZERO(&w_fds);
- FD_SET(state.sock, &r_fds);
- maxfd = state.sock;
-
- /*
- * Initialize this high as event_add_to_select_args()
- * uses a timeval_min() on this and next_event. Fix
- * from Roel van Meer <rolek@alt001.com>.
- */
- t.tv_sec = 999999;
- t.tv_usec = 0;
-
- event_add_to_select_args(winbind_event_context(), &now,
- &r_fds, &w_fds, &t, &maxfd);
- 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_select(maxfd + 1, &r_fds, &w_fds, NULL, tp);
-
- if (run_events(winbind_event_context(), &ret, &r_fds, &w_fds)) {
- /* We got a signal - continue. */
- TALLOC_FREE(frame);
- continue;
- }
-
- 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,("select error occured\n"));
- TALLOC_FREE(frame);
- perror("select");
- _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);
- }