diff options
author | Nirbhay Choubey <nirbhay@mariadb.com> | 2015-06-24 17:02:33 -0400 |
---|---|---|
committer | Nirbhay Choubey <nirbhay@mariadb.com> | 2015-06-24 17:02:33 -0400 |
commit | 0f4478105f5027ce589a0f08c6019d906d632029 (patch) | |
tree | 2e9a7f6f0d27c907861d19d032e076b7c0fd7649 /include | |
parent | 70714d3597ec9ffa742cc9e173d4ad32f294cc51 (diff) | |
download | mariadb-git-0f4478105f5027ce589a0f08c6019d906d632029.tar.gz |
Add close-on-exec flag to open(), socket(), accept() & fopen().
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 |