summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Black <daniel@linux.ibm.com>2020-04-29 13:22:25 +1000
committerVladislav Vaintroub <wlad@mariadb.com>2020-07-06 12:33:35 +0200
commit3efdac2064c5ea5bd58538396d1a7a9fe6f498d1 (patch)
tree7b90ea7e40b94fa265790b9b18e39281938c83a8
parentc43a666662ac71e70bde83e6673ebcb2811887af (diff)
downloadmariadb-git-3efdac2064c5ea5bd58538396d1a7a9fe6f498d1.tar.gz
MDEV-22173: socket accept - test for failure
accept might return an error, including SOCKET_EAGAIN/ SOCKET_EINTR. The caller, usually handle_connections_sockets can these however and invalid file descriptor isn't something to call fcntl on. Thanks to Etienne Guesnet (ATOS) for diagnosis, sample patch description and testing.
-rw-r--r--include/mysql/psi/mysql_socket.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h
index a7397795f77..2ab6932e396 100644
--- a/include/mysql/psi/mysql_socket.h
+++ b/include/mysql/psi/mysql_socket.h
@@ -1048,10 +1048,14 @@ inline_mysql_socket_accept
#else
socket_accept.fd= accept(socket_listen.fd, addr, &addr_length);
#ifdef FD_CLOEXEC
- flags= fcntl(socket_accept.fd, F_GETFD);
- if (flags != -1) {
- flags |= FD_CLOEXEC;
- fcntl(socket_accept.fd, F_SETFD, flags);
+ if (socket_accept.fd != INVALID_SOCKET)
+ {
+ flags= fcntl(socket_accept.fd, F_GETFD);
+ if (flags != -1)
+ {
+ flags |= FD_CLOEXEC;
+ fcntl(socket_accept.fd, F_SETFD, flags);
+ }
}
#endif
#endif
@@ -1070,10 +1074,14 @@ inline_mysql_socket_accept
#else
socket_accept.fd= accept(socket_listen.fd, addr, &addr_length);
#ifdef FD_CLOEXEC
- flags= fcntl(socket_accept.fd, F_GETFD);
- if (flags != -1) {
- flags |= FD_CLOEXEC;
- fcntl(socket_accept.fd, F_SETFD, flags);
+ if (socket_accept.fd != INVALID_SOCKET)
+ {
+ flags= fcntl(socket_accept.fd, F_GETFD);
+ if (flags != -1)
+ {
+ flags |= FD_CLOEXEC;
+ fcntl(socket_accept.fd, F_SETFD, flags);
+ }
}
#endif
#endif