]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/tsocket: remember the first error as tstream_bsd->error
authorStefan Metzmacher <metze@samba.org>
Thu, 13 Oct 2022 14:23:03 +0000 (16:23 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 19 Oct 2022 16:14:36 +0000 (16:14 +0000)
If we found that the connection is broken, there's no point
in trying to use it anymore, so just return the first error we detected.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/tsocket/tsocket_bsd.c

index 8ab2ffb0b839b311d874ea17dda87731c61d2092..72499561f2d89611f443aa0a386f5c216eeb677e 100644 (file)
@@ -1744,6 +1744,7 @@ int _tdgram_unix_socket(const struct tsocket_address *local,
 
 struct tstream_bsd {
        int fd;
+       int error;
 
        void *event_ptr;
        struct tevent_fd *fde;
@@ -1921,7 +1922,19 @@ static ssize_t tstream_bsd_pending_bytes(struct tstream_context *stream)
                return -1;
        }
 
+       if (bsds->error != 0) {
+               errno = bsds->error;
+               return -1;
+       }
+
        ret = tsocket_bsd_pending(bsds->fd);
+       if (ret == -1) {
+               /*
+                * remember the error and don't
+                * allow further requests
+                */
+               bsds->error = errno;
+       }
 
        return ret;
 }
@@ -2029,9 +2042,15 @@ static void tstream_bsd_readv_handler(void *private_data)
        int _count;
        bool ok, retry;
 
+       if (bsds->error != 0) {
+               tevent_req_error(req, bsds->error);
+               return;
+       }
+
        ret = readv(bsds->fd, state->vector, state->count);
        if (ret == 0) {
                /* propagate end of file */
+               bsds->error = EPIPE;
                tevent_req_error(req, EPIPE);
                return;
        }
@@ -2040,6 +2059,13 @@ static void tstream_bsd_readv_handler(void *private_data)
                /* retry later */
                return;
        }
+       if (err != 0) {
+               /*
+                * remember the error and don't
+                * allow further requests
+                */
+               bsds->error = err;
+       }
        if (tevent_req_error(req, err)) {
                return;
        }
@@ -2172,9 +2198,15 @@ static void tstream_bsd_writev_handler(void *private_data)
        int _count;
        bool ok, retry;
 
+       if (bsds->error != 0) {
+               tevent_req_error(req, bsds->error);
+               return;
+       }
+
        ret = writev(bsds->fd, state->vector, state->count);
        if (ret == 0) {
                /* propagate end of file */
+               bsds->error = EPIPE;
                tevent_req_error(req, EPIPE);
                return;
        }
@@ -2183,6 +2215,13 @@ static void tstream_bsd_writev_handler(void *private_data)
                /* retry later */
                return;
        }
+       if (err != 0) {
+               /*
+                * remember the error and don't
+                * allow further requests
+                */
+               bsds->error = err;
+       }
        if (tevent_req_error(req, err)) {
                return;
        }