Commit 21f90371 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

MDEV-18360 Prevent set_max_open_files from allocating too many files

If the rlimit.rlim_cur value returned by getrlimit is not the
RLIM_INFINITY magic constant, but a *very* large number, we can allocate
too many open files. Restrict set_max_open_files to only return at most
max_file_limit, as passed via its parameter.
parent ad220b96
...@@ -52,10 +52,9 @@ static uint set_max_open_files(uint max_file_limit) ...@@ -52,10 +52,9 @@ static uint set_max_open_files(uint max_file_limit)
DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u", DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u",
(uint) rlimit.rlim_cur, (uint) rlimit.rlim_cur,
(uint) rlimit.rlim_max)); (uint) rlimit.rlim_max));
if ((ulonglong) rlimit.rlim_cur == (ulonglong) RLIM_INFINITY) if ((ulonglong) rlimit.rlim_cur == (ulonglong) RLIM_INFINITY ||
rlimit.rlim_cur = max_file_limit; rlimit.rlim_cur >= max_file_limit)
if (rlimit.rlim_cur >= max_file_limit) DBUG_RETURN(max_file_limit);
DBUG_RETURN(rlimit.rlim_cur); /* purecov: inspected */
rlimit.rlim_cur= rlimit.rlim_max= max_file_limit; rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
if (setrlimit(RLIMIT_NOFILE, &rlimit)) if (setrlimit(RLIMIT_NOFILE, &rlimit))
max_file_limit= old_cur; /* Use original value */ max_file_limit= old_cur; /* Use original value */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment