s3:rpc_client: close the socket when pipe is broken
authorStefan Metzmacher <metze@samba.org>
Tue, 6 Apr 2010 12:04:33 +0000 (14:04 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 7 Apr 2010 11:59:07 +0000 (13:59 +0200)
Signed-off-by: Bo Yang <boyang@samba.org>
(similar to commit aa70e44cd0576e5280e24cf35000369a47dd958f)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/rpc_client/rpc_transport_sock.c

index 7115dc4c928461034f4ce8a0e6cf5b4f1a0e6e0a..0e9706d74e4eed677661e0340816bc3138adf076 100644 (file)
@@ -36,6 +36,7 @@ static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *
 }
 
 struct rpc_sock_read_state {
+       struct rpc_transport_sock_state *transp;
        ssize_t received;
 };
 
@@ -56,7 +57,13 @@ static struct async_req *rpc_sock_read_send(TALLOC_CTX *mem_ctx,
                             struct rpc_sock_read_state)) {
                return NULL;
        }
-
+       if (sock_transp->fd == -1) {
+               if (!async_post_ntstatus(result, ev, NT_STATUS_CONNECTION_INVALID)) {
+                       goto fail;
+               }
+               return result;
+       }
+       state->transp = sock_transp;
        subreq = async_recv_send(state, ev, sock_transp->fd, data, size, 0);
        if (subreq == NULL) {
                goto fail;
@@ -82,6 +89,10 @@ static void rpc_sock_read_done(struct tevent_req *subreq)
        state->received = async_recv_recv(subreq, &err);
 
        if (state->received == -1) {
+               if (err == EPIPE) {
+                       close(state->transp->fd);
+                       state->transp->fd = -1;
+               }
                TALLOC_FREE(subreq);
                async_req_nterror(req, map_nt_error_from_unix(err));
                return;
@@ -104,6 +115,7 @@ static NTSTATUS rpc_sock_read_recv(struct async_req *req, ssize_t *preceived)
 }
 
 struct rpc_sock_write_state {
+       struct rpc_transport_sock_state *transp;
        ssize_t sent;
 };
 
@@ -124,6 +136,13 @@ static struct async_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx,
                             struct rpc_sock_write_state)) {
                return NULL;
        }
+       if (sock_transp->fd == -1) {
+               if (!async_post_ntstatus(result, ev, NT_STATUS_CONNECTION_INVALID)) {
+                       goto fail;
+               }
+               return result;
+       }
+       state->transp = sock_transp;
        subreq = async_send_send(state, ev, sock_transp->fd, data, size, 0);
        if (subreq == NULL) {
                goto fail;
@@ -149,6 +168,10 @@ static void rpc_sock_write_done(struct tevent_req *subreq)
        state->sent = async_send_recv(subreq, &err);
 
        if (state->sent == -1) {
+               if (err == EPIPE) {
+                       close(state->transp->fd);
+                       state->transp->fd = -1;
+               }
                TALLOC_FREE(subreq);
                async_req_nterror(req, map_nt_error_from_unix(err));
                return;