diff --git a/src/debug.c b/src/debug.c index 285def16c..1719036a2 100644 --- a/src/debug.c +++ b/src/debug.c @@ -516,10 +516,10 @@ static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appct if (pipe(pipefd) < 0) goto fail_pipe; - if (fcntl(pipefd[0], F_SETFD, fcntl(pipefd[0], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1) + if (fd_set_cloexec(pipefd[0]) == -1) goto fail_fcntl; - if (fcntl(pipefd[1], F_SETFD, fcntl(pipefd[1], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1) + if (fd_set_cloexec(pipefd[1]) == -1) goto fail_fcntl; pid = fork(); diff --git a/src/dns.c b/src/dns.c index 4a776a1ef..29d3cef39 100644 --- a/src/dns.c +++ b/src/dns.c @@ -11,7 +11,6 @@ */ #include -#include #include #include #include @@ -71,7 +70,7 @@ static int dns_connect_nameserver(struct dns_nameserver *ns) } /* Make the socket non blocking */ - fcntl(fd, F_SETFL, O_NONBLOCK); + fd_set_nonblock(fd); /* Add the fd in the fd list and update its parameters */ dgram->t.sock.fd = fd; diff --git a/src/fd.c b/src/fd.c index 529cba739..6b2942d13 100644 --- a/src/fd.c +++ b/src/fd.c @@ -630,7 +630,7 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t if (unlikely(!(fdtab[fd].state & FD_INITIALIZED))) { HA_ATOMIC_OR(&fdtab[fd].state, FD_INITIALIZED); if (!isatty(fd)) - fcntl(fd, F_SETFL, O_NONBLOCK); + fd_set_nonblock(fd); } sent = writev(fd, iovec, vec); HA_ATOMIC_BTR(&fdtab[fd].state, FD_EXCL_SYSCALL_BIT); @@ -788,7 +788,7 @@ static int init_pollers_per_thread() poller_rd_pipe = mypipe[0]; poller_wr_pipe[tid] = mypipe[1]; - fcntl(poller_rd_pipe, F_SETFL, O_NONBLOCK); + fd_set_nonblock(poller_rd_pipe); fd_insert(poller_rd_pipe, poller_pipe_io_handler, poller_pipe_io_handler, tid_bit); fd_insert(poller_wr_pipe[tid], poller_pipe_io_handler, poller_pipe_io_handler, tid_bit); fd_want_recv(poller_rd_pipe); diff --git a/src/log.c b/src/log.c index de9561d84..522c2f602 100644 --- a/src/log.c +++ b/src/log.c @@ -11,7 +11,6 @@ */ #include -#include #include #include #include @@ -1668,7 +1667,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, int level, setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); /* does nothing under Linux, maybe needed for others */ shutdown(*plogfd, SHUT_RD); - fcntl(*plogfd, F_SETFD, fcntl(*plogfd, F_GETFD, FD_CLOEXEC) | FD_CLOEXEC); + fd_set_cloexec(*plogfd); } } diff --git a/src/mworker.c b/src/mworker.c index ccfcb5c6b..1ee93fbd5 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -13,7 +13,6 @@ #define _GNU_SOURCE #include -#include #include #include #include @@ -422,7 +421,7 @@ static int mworker_pipe_register_per_thread() if (tid != 0) return 1; - fcntl(proc_self->ipc_fd[1], F_SETFL, O_NONBLOCK); + fd_set_nonblock(proc_self->ipc_fd[1]); /* In multi-tread, we need only one thread to process * events on the pipe with master */ diff --git a/src/proto_quic.c b/src/proto_quic.c index eb3a316df..2186aa5aa 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -334,7 +333,7 @@ int quic_connect_server(struct connection *conn, int flags) return SF_ERR_PRXCOND; /* it is a configuration limit */ } - if ((fcntl(fd, F_SETFL, O_NONBLOCK)==-1)) { + if (fd_set_nonblock(fd) == -1) { qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); close(fd); conn->err_code = CO_ER_SOCK_ERR; @@ -342,7 +341,7 @@ int quic_connect_server(struct connection *conn, int flags) return SF_ERR_INTERNAL; } - if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) { + if (master == 1 && fd_set_cloexec(fd) == -1) { ha_alert("Cannot set CLOEXEC on client socket.\n"); close(fd); conn->err_code = CO_ER_SOCK_ERR; diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index b244dd1b3..a621ecbea 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -150,7 +149,7 @@ int sockpair_bind_receiver(struct receiver *rx, char **errmsg) goto bind_close_return; } - if (fcntl(rx->fd, F_SETFL, O_NONBLOCK) == -1) { + if (fd_set_nonblock(rx->fd) == -1) { err |= ERR_FATAL | ERR_ALERT; memprintf(errmsg, "cannot make socket non-blocking"); goto bind_close_return; @@ -313,7 +312,7 @@ static int sockpair_connect_server(struct connection *conn, int flags) return SF_ERR_PRXCOND; /* it is a configuration limit */ } - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + if (fd_set_nonblock(fd) == -1) { qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); close(sv[0]); close(sv[1]); @@ -322,7 +321,7 @@ static int sockpair_connect_server(struct connection *conn, int flags) return SF_ERR_INTERNAL; } - if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) { + if (master == 1 && fd_set_cloexec(fd) == -1) { ha_alert("Cannot set CLOEXEC on client socket.\n"); close(sv[0]); close(sv[1]); @@ -469,7 +468,7 @@ struct connection *sockpair_accept_conn(struct listener *l, int *status) int cfd; if ((cfd = recv_fd_uxst(l->rx.fd)) != -1) - DISGUISE(fcntl(cfd, F_SETFL, O_NONBLOCK)); + fd_set_nonblock(cfd); if (likely(cfd != -1)) { /* Perfect, the connection was accepted */ diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 738d2d113..a160b1b87 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -341,7 +340,7 @@ int tcp_connect_server(struct connection *conn, int flags) return SF_ERR_PRXCOND; /* it is a configuration limit */ } - if ((fcntl(fd, F_SETFL, O_NONBLOCK)==-1) || + if (fd_set_nonblock(fd) == -1 || (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) == -1)) { qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); close(fd); @@ -350,7 +349,7 @@ int tcp_connect_server(struct connection *conn, int flags) return SF_ERR_INTERNAL; } - if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) { + if (master == 1 && fd_set_cloexec(fd) == -1) { ha_alert("Cannot set CLOEXEC on client socket.\n"); close(fd); conn->err_code = CO_ER_SOCK_ERR; diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 2db4fa20b..cc98e0d5c 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -269,7 +268,7 @@ static int uxst_connect_server(struct connection *conn, int flags) return SF_ERR_PRXCOND; /* it is a configuration limit */ } - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + if (fd_set_nonblock(fd) == -1) { qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); close(fd); conn->err_code = CO_ER_SOCK_ERR; @@ -277,7 +276,7 @@ static int uxst_connect_server(struct connection *conn, int flags) return SF_ERR_INTERNAL; } - if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) { + if (master == 1 && fd_set_cloexec(fd) == -1) { ha_alert("Cannot set CLOEXEC on client socket.\n"); close(fd); conn->err_code = CO_ER_SOCK_ERR; diff --git a/src/sock.c b/src/sock.c index f4d8ba4d0..6f58aec2f 100644 --- a/src/sock.c +++ b/src/sock.c @@ -13,7 +13,6 @@ #define _GNU_SOURCE #include #include -#include #include #include #include @@ -96,9 +95,9 @@ struct connection *sock_accept_conn(struct listener *l, int *status) { laddr = sizeof(*conn->src); if ((cfd = accept(l->rx.fd, (struct sockaddr*)addr, &laddr)) != -1) { - fcntl(cfd, F_SETFL, O_NONBLOCK); + fd_set_nonblock(cfd); if (master) - fcntl(cfd, F_SETFD, FD_CLOEXEC); + fd_set_cloexec(cfd); } } diff --git a/src/sock_inet.c b/src/sock_inet.c index fa04dfed0..46cc16a1c 100644 --- a/src/sock_inet.c +++ b/src/sock_inet.c @@ -11,7 +11,6 @@ */ #include -#include #include #include @@ -319,7 +318,7 @@ int sock_inet_bind_receiver(struct receiver *rx, char **errmsg) goto bind_close_return; } - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + if (fd_set_nonblock(fd) == -1) { err |= ERR_FATAL | ERR_ALERT; memprintf(errmsg, "cannot make socket non-blocking"); goto bind_close_return; diff --git a/src/sock_unix.c b/src/sock_unix.c index 45ba89f46..143295e79 100644 --- a/src/sock_unix.c +++ b/src/sock_unix.c @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -233,7 +232,7 @@ int sock_unix_bind_receiver(struct receiver *rx, char **errmsg) goto bind_close_return; } - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + if (fd_set_nonblock(fd) == -1) { err |= ERR_FATAL | ERR_ALERT; memprintf(errmsg, "cannot make socket non-blocking"); goto bind_close_return;