winbind: separate child response sock write
authorDavid Disseldorp <ddiss@samba.org>
Thu, 14 Mar 2013 18:49:04 +0000 (19:49 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 15 Apr 2013 16:15:23 +0000 (18:15 +0200)
For consistency with request read side.

source3/winbindd/winbindd_dual.c

index 0cd178567f7de547897bdc0d3728741968cc454a..7e06142c56b6e044616ea18d2bb8d4f983744b55 100644 (file)
@@ -83,6 +83,31 @@ static NTSTATUS child_read_request(int sock, struct winbindd_request *wreq)
        return status;
 }
 
+static NTSTATUS child_write_response(int sock, struct winbindd_response *wrsp)
+{
+       struct iovec iov[2];
+       int iov_count;
+
+       iov[0].iov_base = (void *)wrsp;
+       iov[0].iov_len = sizeof(struct winbindd_response);
+       iov_count = 1;
+
+       if (wrsp->length > sizeof(struct winbindd_response)) {
+               iov[1].iov_base = (void *)wrsp->extra_data.data;
+               iov[1].iov_len = wrsp->length-iov[0].iov_len;
+               iov_count = 2;
+       }
+
+       DEBUG(10, ("Writing %d bytes to parent\n", (int)wrsp->length));
+
+       if (write_data_iov(sock, iov, iov_count) != wrsp->length) {
+               DEBUG(0, ("Could not write result\n"));
+               return NT_STATUS_INVALID_HANDLE;
+       }
+
+       return NT_STATUS_OK;
+}
+
 /*
  * Do winbind child async request. This is not simply wb_simple_trans. We have
  * to do the queueing ourselves because while a request is queued, the child
@@ -1460,8 +1485,6 @@ static bool fork_domain_child(struct winbindd_child *child)
                struct timeval t;
                struct timeval *tp;
                TALLOC_CTX *frame = talloc_stackframe();
-               struct iovec iov[2];
-               int iov_count;
 
                if (run_events_poll(winbind_event_context(), 0, NULL, 0)) {
                        TALLOC_FREE(frame);
@@ -1550,24 +1573,9 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                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);
+               status = child_write_response(state.sock, state.response);
+               if (!NT_STATUS_IS_OK(status)) {
+                       _exit(1);
                }
                TALLOC_FREE(frame);
        }