]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: init: always ensure that global.rlimit_nofile matches actual limits
authorWilly Tarreau <w@1wt.eu>
Tue, 21 Jun 2016 09:48:18 +0000 (11:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Jun 2016 16:10:50 +0000 (18:10 +0200)
global.rlimit_nofile contains the mxa number of file descriptors that
can be allocated, except if the user is not allowed to reach this limit,
where it still contains the initially requested value. It is important
that this value always matches what is really configured so that it is
properly reported in the stats and that we can use it later to close
all FDs without wasting time closing impossible FDs.

This fix may be backported to 1.6 and 1.5.

src/haproxy.c

index c6d1505d98c57c27b40c577cb67e0ae5fc8df8c3..2612e29b9f2f61e6413133fd330f6bf090d5ca3c 100644 (file)
@@ -1769,7 +1769,10 @@ int main(int argc, char **argv)
        if (global.rlimit_nofile) {
                limit.rlim_cur = limit.rlim_max = global.rlimit_nofile;
                if (setrlimit(RLIMIT_NOFILE, &limit) == -1) {
-                       Warning("[%s.main()] Cannot raise FD limit to %d.\n", argv[0], global.rlimit_nofile);
+                       /* try to set it to the max possible at least */
+                       getrlimit(RLIMIT_NOFILE, &limit);
+                       Warning("[%s.main()] Cannot raise FD limit to %d, limit is %d.\n", argv[0], global.rlimit_nofile, (int)limit.rlim_cur);
+                       global.rlimit_nofile = limit.rlim_cur;
                }
        }