mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-8743: mysqld port/socket - FD_CLOEXEC if no SOCK_CLOEXEC
In MDEV-8743, the port/socket of mysqld was changed to set FD_CLOEXEC. The existing mysql_socket_socket function already set that with SOCK_CLOEXEC when the socket was created. So here we move the fcntl functionality to the mysql_socket_socket as port/socket are the only callers. Preprocessor checks of SOCK_CLOEXEC cannot be done as its a 0 if not there and SOCK_CLOEXEC (being the value of the enum in bits/socket_type.h) Preprocesssor logic for arithmetic and non-arithmetic defines are hard/nonportable/ugly to read. As such we just check in my_global.h and define HAVE_SOCK_CLOEXEC if we have it. There was a disparity in behaviour between defined(WITH_WSREP) and not depending on the OS, so the WITH_WSREP condition was removed from setting calling fcntl. All sockets are now maked SOCK_CLOEXEC/FD_CLOEXEC. strace of mysqld with SOCK_CLOEXEC: socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 10 write(2, "180419 14:52:40 [Note] Server socket created on IP: '127.0.0.1'.\n", 65180419 14:52:40 [Note] Server socket created on IP: '127.0.0.1'. ) = 65 setsockopt(10, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(10, {sa_family=AF_INET, sin_port=htons(16020), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 listen(10, 150) = 0 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 11 write(2, "180419 14:52:40 [Note] Server socket created on IP: '127.0.0.1'.\n", 65180419 14:52:40 [Note] Server socket created on IP: '127.0.0.1'. ) = 65 setsockopt(11, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(11, {sa_family=AF_INET, sin_port=htons(16021), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 listen(11, 150) = 0 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 12 unlink("/home/dan/repos/build-mariadb-server-10.0/mysql-test/var/tmp/mysqld.1.sock") = -1 ENOENT (No such file or directory) setsockopt(12, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 umask(000) = 006 bind(12, {sa_family=AF_UNIX, sun_path="/home/dan/repos/build-mariadb-server-10.0/mysql-test/var/tmp/mysqld.1.sock"}, 110) = 0 umask(006) = 000 listen(12, 150) = 0
This commit is contained in:
@@ -608,6 +608,8 @@ typedef SOCKET_SIZE_TYPE size_socket;
|
|||||||
#endif
|
#endif
|
||||||
#ifndef SOCK_CLOEXEC
|
#ifndef SOCK_CLOEXEC
|
||||||
#define SOCK_CLOEXEC 0
|
#define SOCK_CLOEXEC 0
|
||||||
|
#else
|
||||||
|
#define HAVE_SOCK_CLOEXEC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* additional file share flags for win32 */
|
/* additional file share flags for win32 */
|
||||||
|
@@ -562,6 +562,12 @@ inline_mysql_socket_socket
|
|||||||
(key, (const my_socket*)&mysql_socket.fd, NULL, 0);
|
(key, (const my_socket*)&mysql_socket.fd, NULL, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* SOCK_CLOEXEC isn't always a number - can't preprocessor compare */
|
||||||
|
#if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) && !defined(HAVE_SOCK_CLOEXEC)
|
||||||
|
(void) fcntl(mysql_socket.fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
|
|
||||||
return mysql_socket;
|
return mysql_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2593,10 +2593,6 @@ static MYSQL_SOCKET activate_tcp_port(uint port)
|
|||||||
socket_errno);
|
socket_errno);
|
||||||
unireg_abort(1);
|
unireg_abort(1);
|
||||||
}
|
}
|
||||||
#if defined(WITH_WSREP) && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
|
|
||||||
(void) fcntl(mysql_socket_getfd(ip_sock), F_SETFD, FD_CLOEXEC);
|
|
||||||
#endif /* WITH_WSREP */
|
|
||||||
|
|
||||||
DBUG_RETURN(ip_sock);
|
DBUG_RETURN(ip_sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2714,9 +2710,6 @@ static void network_init(void)
|
|||||||
if (mysql_socket_listen(unix_sock,(int) back_log) < 0)
|
if (mysql_socket_listen(unix_sock,(int) back_log) < 0)
|
||||||
sql_print_warning("listen() on Unix socket failed with error %d",
|
sql_print_warning("listen() on Unix socket failed with error %d",
|
||||||
socket_errno);
|
socket_errno);
|
||||||
#if defined(WITH_WSREP) && defined(HAVE_FCNTL)
|
|
||||||
(void) fcntl(mysql_socket_getfd(unix_sock), F_SETFD, FD_CLOEXEC);
|
|
||||||
#endif /* WITH_WSREP */
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
DBUG_PRINT("info",("server started"));
|
DBUG_PRINT("info",("server started"));
|
||||||
|
Reference in New Issue
Block a user