diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/my_global.h | 6 | ||||
-rw-r--r-- | include/mysql/psi/mysql_socket.h | 24 |
2 files changed, 29 insertions, 1 deletions
diff --git a/include/my_global.h b/include/my_global.h index e9a472e686e..b3deba3c565 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -609,6 +609,12 @@ typedef SOCKET_SIZE_TYPE size_socket; #ifndef O_NOFOLLOW #define O_NOFOLLOW 0 #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC 0 +#endif /* additional file share flags for win32 */ #ifdef __WIN__ diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index e1d56539f85..6f37e012f1f 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -553,7 +553,7 @@ inline_mysql_socket_socket int domain, int type, int protocol) { MYSQL_SOCKET mysql_socket= MYSQL_INVALID_SOCKET; - mysql_socket.fd= socket(domain, type, protocol); + mysql_socket.fd= socket(domain, type | SOCK_CLOEXEC, protocol); #ifdef HAVE_PSI_SOCKET_INTERFACE if (likely(mysql_socket.fd != INVALID_SOCKET)) @@ -1013,6 +1013,8 @@ inline_mysql_socket_accept #endif MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len) { + int flags; + MYSQL_SOCKET socket_accept= MYSQL_INVALID_SOCKET; socklen_t addr_length= (addr_len != NULL) ? *addr_len : 0; @@ -1026,7 +1028,17 @@ inline_mysql_socket_accept (&state, socket_listen.m_psi, PSI_SOCKET_CONNECT, (size_t)0, src_file, src_line); /* Instrumented code */ +#ifdef HAVE_ACCEPT4 + socket_accept.fd= accept4(socket_listen.fd, addr, &addr_length, + SOCK_CLOEXEC); +#else socket_accept.fd= accept(socket_listen.fd, addr, &addr_length); + flags= fcntl(socket_accept.fd, F_GETFD); + if (flags != -1) { + flags |= FD_CLOEXEC; + fcntl(socket_accept.fd, F_SETFD, flags); + } +#endif /* Instrumentation end */ if (locker != NULL) @@ -1036,7 +1048,17 @@ inline_mysql_socket_accept #endif { /* Non instrumented code */ +#ifdef HAVE_ACCEPT4 + socket_accept.fd= accept4(socket_listen.fd, addr, &addr_length, + SOCK_CLOEXEC); +#else socket_accept.fd= accept(socket_listen.fd, addr, &addr_length); + flags= fcntl(socket_accept.fd, F_GETFD); + if (flags != -1) { + flags |= FD_CLOEXEC; + fcntl(socket_accept.fd, F_SETFD, flags); + } +#endif } #ifdef HAVE_PSI_SOCKET_INTERFACE |