socket: set FD_CLOEXEC on all sockets

For more information, see http://udrepper.livejournal.com/20407.html

BUG: 1236272
Change-Id: I25a645c10bdbe733a81d53cb714eb036251f8129
fixes: bz#1236272
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
This commit is contained in:
Krishnan Parthasarathi 2018-10-09 15:17:57 +05:30 committed by Raghavendra G
parent 4511435fd3
commit 23e96fd93c
4 changed files with 21 additions and 3 deletions

View File

@ -1051,6 +1051,7 @@ sys_unlink
sys_utimensat
sys_write
sys_writev
sys_socket
tbf_init
tbf_throttle
timespec_now

View File

@ -727,3 +727,17 @@ sys_fallocate(int fd, int mode, off_t offset, off_t len)
errno = ENOSYS;
return -1;
}
int
sys_socket(int domain, int type, int protocol)
{
#ifdef SOCK_CLOEXEC
return socket(domain, type | SOCK_CLOEXEC, protocol);
#endif
int fd = -1;
fd = socket(domain, type, protocol);
if (fd >= 0)
fcntl(fd, F_SETFD, FD_CLOEXEC);
return fd;
}

View File

@ -221,4 +221,7 @@ sys_pread(int fd, void *buf, size_t count, off_t offset);
ssize_t
sys_pwrite(int fd, const void *buf, size_t count, off_t offset);
int
sys_socket(int domain, int type, int protocol);
#endif /* __SYSCALL_H__ */

View File

@ -886,7 +886,7 @@ __socket_server_bind(rpc_transport_t *this)
if (AF_UNIX == SA(&this->myinfo.sockaddr)->sa_family) {
memcpy(&unix_addr, SA(&this->myinfo.sockaddr),
this->myinfo.sockaddr_len);
reuse_check_sock = socket(AF_UNIX, SOCK_STREAM, 0);
reuse_check_sock = sys_socket(AF_UNIX, SOCK_STREAM, 0);
if (reuse_check_sock >= 0) {
ret = connect(reuse_check_sock, SA(&unix_addr),
this->myinfo.sockaddr_len);
@ -3342,7 +3342,7 @@ socket_connect(rpc_transport_t *this, int port)
memcpy(&this->peerinfo.sockaddr, &sock_union.storage, sockaddr_len);
this->peerinfo.sockaddr_len = sockaddr_len;
priv->sock = socket(sa_family, SOCK_STREAM, 0);
priv->sock = sys_socket(sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)",
strerror(errno));
@ -3614,7 +3614,7 @@ socket_listen(rpc_transport_t *this)
memcpy(&myinfo->sockaddr, &sockaddr, sockaddr_len);
myinfo->sockaddr_len = sockaddr_len;
priv->sock = socket(sa_family, SOCK_STREAM, 0);
priv->sock = sys_socket(sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log(this->name, GF_LOG_ERROR, "socket creation failed (%s)",