mariadb/include/mysql/psi
Daniel Black ccd566af20 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
2018-04-19 14:34:46 +10:00
..
mysql_file.h Merge branch '5.5' into 10.0 2017-04-21 18:34:06 +02:00
mysql_idle.h
mysql_socket.h MDEV-8743: mysqld port/socket - FD_CLOEXEC if no SOCK_CLOEXEC 2018-04-19 14:34:46 +10:00
mysql_stage.h
mysql_statement.h
mysql_table.h
mysql_thread.h
psi.h Merge branch '5.5' into 10.0 2017-03-03 01:37:54 +02:00
psi_abi_v0.h
psi_abi_v0.h.pp
psi_abi_v1.h
psi_abi_v1.h.pp Merge branch 'merge/merge-perfschema-5.6' into 10.0 2015-12-13 17:19:18 +01:00
psi_abi_v2.h
psi_abi_v2.h.pp Merge branch '5.5' into 10.0 2015-06-11 20:20:35 +02:00