]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: fd: make sure my_closefrom() doesn't miss some FDs
authorWilly Tarreau <w@1wt.eu>
Fri, 22 Feb 2019 08:07:42 +0000 (09:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 Feb 2019 08:07:42 +0000 (09:07 +0100)
The optimized my_closefrom() implementation introduced with previous commit
9188ac60e ("MINOR: fd: implement an optimised my_closefrom() function")
has a small bug causing it to miss some FDs at the end of each batch.
The reason is that poll() returns the number of non-zero events, so
it contains the size of the batch minus the FDs to close. Thus if the
FDs to close are at the beginning they'll be seen but if they're at the
end after all other closed ones, the returned count will not cover them.

No backport is needed.

src/fd.c

index 33b8900f3b47f467a68922217edd1e66d31801e0..7fdd56b40c24daf78340e31be64fdda941f32f9d 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -509,6 +509,9 @@ void my_closefrom(int start)
                                break;
                } while (errno == EAGAIN || errno == EINTR || errno == ENOMEM);
 
+               if (ret)
+                       ret = fd - start;
+
                for (idx = 0; idx < ret; idx++) {
                        if (poll_events[idx].revents & POLLNVAL)
                                continue; /* already closed */