MDEV-32686: Signal hander- minimise resource limit output.

Most resource limit information is excessive, particularly
limits that aren't limited.

We restructure the output by considering the Linux format
of /proc/limits which had its soft limits beginning at offset
26. "u"limited lines are skipped.

Example output:

Resource Limits (excludes unlimited resources):
Limit                     Soft Limit           Hard Limit           Units
Max stack size            8388608              unlimited            bytes
Max processes             127235               127235               processes
Max open files            32198                32198                files
Max locked memory         8388608              8388608              bytes
Max pending signals       127235               127235               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0

This is 8 lines less that what was before.

The FreeBSD limits file was /proc/curproc/rlimit and a different format
so a loss of non-Linux proc enabled OSes isn't expected.
This commit is contained in:
Daniel Black 2023-11-10 11:59:06 +11:00
parent 801587c821
commit 965e65d6bb

View file

@ -71,20 +71,40 @@ static inline void output_core_info()
(int) len, buff);
}
#ifdef __FreeBSD__
if ((fd= open("/proc/curproc/rlimit", O_RDONLY, MYF(0))) >= 0)
if ((fd= open("/proc/curproc/rlimit", O_RDONLY)) >= 0)
#else
if ((fd= open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0)
if ((fd= open("/proc/self/limits", O_RDONLY)) >= 0)
#endif
{
my_safe_printf_stderr("Resource Limits:\n");
while ((len= read(fd, (uchar*)buff, sizeof(buff))) > 0)
{
my_write_stderr(buff, len);
}
char *endline= buff;
ssize_t remain_len= len= read(fd, buff, sizeof(buff));
close(fd);
my_safe_printf_stderr("Resource Limits (excludes unlimited resources):\n");
/* first line, header */
endline= (char *) memchr(buff, '\n', remain_len);
if (endline)
{
endline++;
remain_len= buff + len - endline;
my_safe_printf_stderr("%.*s", (int) (endline - buff), buff);
while (remain_len > 27)
{
char *newendline= (char *) memchr(endline, '\n', remain_len);
if (!newendline)
break;
*newendline= '\0';
newendline++;
if (endline[26] != 'u') /* skip unlimited limits */
my_safe_printf_stderr("%s\n", endline);
remain_len-= newendline - endline;
endline= newendline;
}
}
}
#ifdef __linux__
if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0)
if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0)
{
len= read(fd, (uchar*)buff, sizeof(buff));
my_safe_printf_stderr("Core pattern: %.*s\n", (int) len, buff);