|
23 | 23 |
|
24 | 24 | #include <config.h> |
25 | 25 |
|
| 26 | +#include <sys/resource.h> |
| 27 | +#include <sys/socket.h> |
26 | 28 | #include <sys/stat.h> |
27 | 29 | #include <sys/types.h> |
28 | | -#include <sys/socket.h> |
29 | 30 | #include <netinet/in.h> |
30 | 31 | #include <netinet/tcp.h> |
31 | 32 | #include <arpa/inet.h> |
@@ -1834,6 +1835,36 @@ write_pidfile(void) |
1834 | 1835 | debug_return; |
1835 | 1836 | } |
1836 | 1837 |
|
| 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 | + |
1837 | 1868 | /* |
1838 | 1869 | * Fork, detach from the terminal and write pid file unless nofork set. |
1839 | 1870 | */ |
@@ -1999,6 +2030,9 @@ main(int argc, char *argv[]) |
1999 | 2030 | if (!logsrvd_conf_read(conf_file)) |
2000 | 2031 | return EXIT_FAILURE; |
2001 | 2032 |
|
| 2033 | + /* Crank the open file limit to the maximum value allowed. */ |
| 2034 | + unlimit_nofile(); |
| 2035 | + |
2002 | 2036 | if ((evbase = sudo_ev_base_alloc()) == NULL) |
2003 | 2037 | sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); |
2004 | 2038 |
|
|
0 commit comments