Skip to content

Commit 31bcdec

Browse files
committed
Set the open file descriptor limit to the maximum allowed value.
Each connection can require up to 9 descriptors.
1 parent bf722e1 commit 31bcdec

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

logsrvd/logsrvd.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323

2424
#include <config.h>
2525

26+
#include <sys/resource.h>
27+
#include <sys/socket.h>
2628
#include <sys/stat.h>
2729
#include <sys/types.h>
28-
#include <sys/socket.h>
2930
#include <netinet/in.h>
3031
#include <netinet/tcp.h>
3132
#include <arpa/inet.h>
@@ -1834,6 +1835,36 @@ write_pidfile(void)
18341835
debug_return;
18351836
}
18361837

1838+
/*
1839+
* Increase the number of open files to the maximum value.
1840+
*/
1841+
static void
1842+
unlimit_nofile(void)
1843+
{
1844+
struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
1845+
struct rlimit nofilelimit;
1846+
debug_decl(unlimit_nofile, SUDO_DEBUG_UTIL);
1847+
1848+
if (getrlimit(RLIMIT_NOFILE, &nofilelimit) != 0) {
1849+
sudo_warn("getrlimit(RLIMIT_NOFILE)");
1850+
debug_return;
1851+
}
1852+
sudo_debug_printf(SUDO_DEBUG_INFO,
1853+
"RLIMIT_NOFILE [%lld, %lld] -> [inf, inf]",
1854+
(long long)nofilelimit.rlim_cur, (long long)nofilelimit.rlim_max);
1855+
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
1856+
/* Unable to set to infinity, set to max instead. */
1857+
rl.rlim_cur = rl.rlim_max = nofilelimit.rlim_max;
1858+
sudo_debug_printf(SUDO_DEBUG_INFO,
1859+
"RLIMIT_NOFILE [%lld, %lld] -> [%lld, %lld]",
1860+
(long long)nofilelimit.rlim_cur, (long long)nofilelimit.rlim_max,
1861+
(long long)rl.rlim_cur, (long long)rl.rlim_max);
1862+
if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
1863+
sudo_warn("setrlimit(RLIMIT_NOFILE)");
1864+
}
1865+
debug_return;
1866+
}
1867+
18371868
/*
18381869
* Fork, detach from the terminal and write pid file unless nofork set.
18391870
*/
@@ -1999,6 +2030,9 @@ main(int argc, char *argv[])
19992030
if (!logsrvd_conf_read(conf_file))
20002031
return EXIT_FAILURE;
20012032

2033+
/* Crank the open file limit to the maximum value allowed. */
2034+
unlimit_nofile();
2035+
20022036
if ((evbase = sudo_ev_base_alloc()) == NULL)
20032037
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
20042038

0 commit comments

Comments
 (0)