From: Willy Tarreau Date: Wed, 4 Nov 2020 12:52:22 +0000 (+0100) Subject: MINOR: fd: add fd_want_recv_safe() X-Git-Tag: v2.3.0~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e98e28eb06f907fc3a7a5599b74d5d85b98d9ca;p=thirdparty%2Fhaproxy.git MINOR: fd: add fd_want_recv_safe() This does the same as fd_want_recv() except that it does check for fd_updt[] to be allocated, as this may be called during early listener initialization. Previously we used to check fd_updt[] before calling fd_want_recv() but this is not correct since it does not update the FD flags. This method will be safer. --- diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 5300fd4dc5..9492c3ed0b 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -288,6 +288,18 @@ static inline void fd_want_recv(int fd) updt_fd_polling(fd); } +/* Prepare FD to try to receive, and only create update if fd_updt exists + * (essentially for receivers during early boot). + */ +static inline void fd_want_recv_safe(int fd) +{ + if ((fdtab[fd].state & FD_EV_ACTIVE_R) || + HA_ATOMIC_BTS(&fdtab[fd].state, FD_EV_ACTIVE_R_BIT)) + return; + if (fd_updt) + updt_fd_polling(fd); +} + /* Prepare FD to try to send */ static inline void fd_want_send(int fd) {