From 965e65d6bb5649f6301e777637e06b17117a40cd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 10 Nov 2023 11:59:06 +1100 Subject: [PATCH] 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. --- sql/signal_handler.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 1200a5a1608..20dcbb4fa89 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -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);