diff options
| author | Nalin Dahyabhai <nalin@dahyabhai.net> | 2014-01-28 11:24:27 +0100 |
|---|---|---|
| committer | Andreas Schneider <asn@samba.org> | 2014-01-28 13:23:49 +0100 |
| commit | 27b2055291caf67c6a23e829f596cc6751ce5aad (patch) | |
| tree | 09ffa7ebcea4b6c99d2d854463ec986ce684bdd7 /src | |
| parent | 1462a69c0a96605081f9f1c0dc5bb54aa98aa202 (diff) | |
| download | socket_wrapper-27b2055291caf67c6a23e829f596cc6751ce5aad.tar.gz socket_wrapper-27b2055291caf67c6a23e829f596cc6751ce5aad.tar.xz socket_wrapper-27b2055291caf67c6a23e829f596cc6751ce5aad.zip | |
src: Try to recover when writing to fd returns ENOTSOCK.
When attempting to write to 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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/socket_wrapper.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 4b9f200..bc84479 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -2772,7 +2772,15 @@ static ssize_t swrap_sendmsg_before(int fd, if (si->bound == 0) { ret = swrap_auto_bind(fd, si, si->family); - if (ret == -1) return -1; + if (ret == -1) { + if (errno == ENOTSOCK) { + swrap_remove_stale(fd); + return -ENOTSOCK; + } else { + SWRAP_LOG(SWRAP_LOG_ERROR, "swrap_sendmsg_before failed"); + return -1; + } + } } if (!si->defer_connect) { @@ -3144,6 +3152,7 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, struct sockaddr_un un_addr; const struct sockaddr_un *to_un = NULL; ssize_t ret; + int rc; struct socket_info *si = find_socket_info(s); int bcast = 0; @@ -3165,8 +3174,10 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, msg.msg_flags = 0; /* flags on received message */ #endif - ret = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, &to_un, &to, &bcast); - if (ret == -1) return -1; + rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, &to_un, &to, &bcast); + if (rc < 0) { + return -1; + } buf = msg.msg_iov[0].iov_base; len = msg.msg_iov[0].iov_len; @@ -3340,6 +3351,7 @@ static ssize_t swrap_send(int s, const void *buf, size_t len, int flags) struct iovec tmp; struct sockaddr_un un_addr; ssize_t ret; + int rc; struct socket_info *si = find_socket_info(s); if (!si) { @@ -3360,8 +3372,10 @@ static ssize_t swrap_send(int s, const void *buf, size_t len, int flags) msg.msg_flags = 0; /* flags on received message */ #endif - ret = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, NULL, NULL, NULL); - if (ret == -1) return -1; + rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, NULL, NULL, NULL); + if (rc < 0) { + return -1; + } buf = msg.msg_iov[0].iov_base; len = msg.msg_iov[0].iov_len; @@ -3444,6 +3458,7 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) const struct sockaddr_un *to_un = NULL; const struct sockaddr *to = NULL; ssize_t ret; + int rc; struct socket_info *si = find_socket_info(s); int bcast = 0; @@ -3467,8 +3482,10 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) msg.msg_flags = omsg->msg_flags; /* flags on received message */ #endif - ret = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, &to_un, &to, &bcast); - if (ret == -1) return -1; + rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, &to_un, &to, &bcast); + if (rc < 0) { + return -1; + } if (bcast) { struct stat st; @@ -3598,6 +3615,7 @@ static ssize_t swrap_writev(int s, const struct iovec *vector, int count) struct iovec tmp; struct sockaddr_un un_addr; ssize_t ret; + int rc; struct socket_info *si = find_socket_info(s); if (!si) { @@ -3618,8 +3636,13 @@ static ssize_t swrap_writev(int s, const struct iovec *vector, int count) msg.msg_flags = 0; /* flags on received message */ #endif - ret = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, NULL, NULL, NULL); - if (ret == -1) return -1; + rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, NULL, NULL, NULL); + if (rc < 0) { + if (rc == -ENOTSOCK) { + return libc_readv(s, vector, count); + } + return -1; + } ret = libc_writev(s, msg.msg_iov, msg.msg_iovlen); |
