mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-15 07:54:33 +00:00
MEDIUM: listeners: set O_CLOEXEC on the accepted FDs
Set the O_CLOEXEC flag on the accept, useful to avoid an FD leak in the master process, since it reexecutes itself during a reload
This commit is contained in:
parent
4e8450b7d6
commit
0b3e849a48
@ -545,7 +545,7 @@ void listener_accept(int fd)
|
||||
/* with sockpair@ we don't want to do an accept */
|
||||
if (unlikely(l->addr.ss_family == AF_CUST_SOCKPAIR)) {
|
||||
if ((cfd = recv_fd_uxst(fd)) != -1)
|
||||
fcntl(cfd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(cfd, F_SETFL, O_NONBLOCK|O_CLOEXEC);
|
||||
} else
|
||||
|
||||
#ifdef USE_ACCEPT4
|
||||
@ -553,12 +553,12 @@ void listener_accept(int fd)
|
||||
* fallback to the legacy accept() + fcntl().
|
||||
*/
|
||||
if (unlikely(accept4_broken ||
|
||||
((cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK)) == -1 &&
|
||||
((cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK|SOCK_CLOEXEC)) == -1 &&
|
||||
(errno == ENOSYS || errno == EINVAL || errno == EBADF) &&
|
||||
(accept4_broken = 1))))
|
||||
#endif
|
||||
if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) != -1)
|
||||
fcntl(cfd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(cfd, F_SETFL, O_NONBLOCK|O_CLOEXEC);
|
||||
|
||||
if (unlikely(cfd == -1)) {
|
||||
switch (errno) {
|
||||
|
Loading…
Reference in New Issue
Block a user