summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@dahyabhai.net>2014-01-28 11:25:40 +0100
committerAndreas Schneider <asn@samba.org>2014-01-28 13:24:00 +0100
commitde94be7e4b83283f3b46320706fef19b8203b52c (patch)
tree78b521c24825bdaa5059c95a035b0a3b971ecad8
parent27b2055291caf67c6a23e829f596cc6751ce5aad (diff)
downloadsocket_wrapper-de94be7e4b83283f3b46320706fef19b8203b52c.tar.gz
socket_wrapper-de94be7e4b83283f3b46320706fef19b8203b52c.tar.xz
socket_wrapper-de94be7e4b83283f3b46320706fef19b8203b52c.zip
src: Try to recover when reading from a fd returns ENOTSOCK.
When attempting to read from a descriptor, if an underlying autobind fails because it's not a socket, stop intercepting uses of that descriptor. Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--src/socket_wrapper.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index bc84479..0bfa838 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2936,7 +2936,20 @@ static int swrap_recvmsg_before(int fd,
if (si->bound == 0) {
ret = swrap_auto_bind(fd, si, si->family);
if (ret == -1) {
- return -1;
+ /*
+ * When attempting to read or write to a
+ * descriptor, if an underlying autobind fails
+ * because it's not a socket, stop intercepting
+ * uses of that descriptor.
+ */
+ if (errno == ENOTSOCK) {
+ swrap_remove_stale(fd);
+ return -ENOTSOCK;
+ } else {
+ SWRAP_LOG(SWRAP_LOG_ERROR,
+ "swrap_recvmsg_before failed");
+ return -1;
+ }
}
}
break;
@@ -3094,7 +3107,7 @@ static ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags,
#endif
tret = swrap_recvmsg_before(s, si, &msg, &tmp);
- if (tret == -1) {
+ if (tret < 0) {
return -1;
}
@@ -3261,8 +3274,7 @@ static ssize_t swrap_recv(int s, void *buf, size_t len, int flags)
#endif
tret = swrap_recvmsg_before(s, si, &msg, &tmp);
- if (tret == -1) {
- SWRAP_LOG(SWRAP_LOG_ERROR, "swrap_recvmsg_before failed");
+ if (tret < 0) {
return -1;
}
@@ -3318,8 +3330,10 @@ static ssize_t swrap_read(int s, void *buf, size_t len)
#endif
tret = swrap_recvmsg_before(s, si, &msg, &tmp);
- if (tret == -1) {
- SWRAP_LOG(SWRAP_LOG_ERROR, "swrap_recvmsg_before failed");
+ if (tret < 0) {
+ if (tret == -ENOTSOCK) {
+ return libc_read(s, buf, len);
+ }
return -1;
}
@@ -3427,7 +3441,7 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
#endif
rc = swrap_recvmsg_before(s, si, &msg, &tmp);
- if (rc == -1) {
+ if (rc < 0) {
return -1;
}
@@ -3586,7 +3600,10 @@ static ssize_t swrap_readv(int s, const struct iovec *vector, int count)
#endif
rc = swrap_recvmsg_before(s, si, &msg, &tmp);
- if (rc == -1) {
+ if (rc < 0) {
+ if (rc == -ENOTSOCK) {
+ return libc_readv(s, vector, count);
+ }
return -1;
}