summaryrefslogtreecommitdiff
path: root/sql/signal_handler.cc
diff options
context:
space:
mode:
authorDaniel Black <grooverdan@users.sourceforge.net>2018-01-02 12:00:55 +1100
committerSergei Golubchik <serg@mariadb.org>2019-05-01 18:18:00 +0200
commitdc8e15db7e170964699dec7b5214d20200b4b182 (patch)
tree16aebd61c7258a1e2405f2cea1d65127c0ffff33 /sql/signal_handler.cc
parentb953bf7eb2cbebf74b1f8861f4c45a789d365f28 (diff)
downloadmariadb-git-dc8e15db7e170964699dec7b5214d20200b4b182.tar.gz
MDEV-15051: signal handler - output information about the core generation
The working directory, resource limits and core pattern will aid the user finding a core file in the case of failure. While the core file size is most relevant however other resource limits may give a clue as the the cause of the fatal signal so include them also. As signal handler functions are limited, proc filesystem reads/ readlink calls are used instead of the more obvious getcwd/getrlimits functions which aren't listed as signal safe. Results in output of the form: Writing a core file: working directory at /tmp/datadir Resource Limits: Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size unlimited unlimited bytes Max resident set unlimited unlimited bytes Max processes 47194 47194 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 47194 47194 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us Core pattern: |/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t %P %I Segmentation fault (core dumped) Closes #537
Diffstat (limited to 'sql/signal_handler.cc')
-rw-r--r--sql/signal_handler.cc46
1 files changed, 42 insertions, 4 deletions
diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc
index 68e801d5885..6c0220b1254 100644
--- a/sql/signal_handler.cc
+++ b/sql/signal_handler.cc
@@ -30,6 +30,10 @@
#define SIGNAL_FMT "signal %d"
#endif
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
/*
We are handling signals/exceptions in this file.
Any global variables we read should be 'volatile sig_atomic_t'
@@ -44,6 +48,43 @@ extern volatile sig_atomic_t ld_assume_kernel_is_set;
extern const char *optimizer_switch_names[];
+static inline void output_core_info()
+{
+ /* proc is optional on some BSDs so it can't hurt to look */
+#ifdef HAVE_READLINK
+ char buff[PATH_MAX];
+ ssize_t len;
+ int fd;
+ if ((len= readlink("/proc/self/cwd", buff, sizeof(buff))) >= 0)
+ {
+ my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n",
+ (int) len, buff);
+ }
+ if ((fd= my_open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0)
+ {
+ my_safe_printf_stderr("Resource Limits:\n");
+ while ((len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0))) > 0)
+ {
+ my_write_stderr(buff, len);
+ }
+ my_close(fd, MYF(0));
+ }
+#ifdef __linux__
+ if ((fd= my_open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0)
+ {
+ len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0));
+ my_safe_printf_stderr("Core pattern: %.*s\n", (int) len, buff);
+ my_close(fd, MYF(0));
+ }
+#endif
+#else
+ char buff[80];
+ my_getwd(buff, sizeof(buff), 0);
+ my_safe_printf_stderr("Writing a core file at %s\n", buff);
+ fflush(stderr);
+#endif
+}
+
/**
* Handler for fatal signals on POSIX, exception handler on Windows.
*
@@ -295,13 +336,10 @@ extern "C" sig_handler handle_fatal_signal(int sig)
}
#endif
+ output_core_info();
#ifdef HAVE_WRITE_CORE
if (test_flags & TEST_CORE_ON_SIGNAL)
{
- char buff[80];
- my_getwd(buff, sizeof(buff), 0);
- my_safe_printf_stderr("Writing a core file at %s\n", buff);
- fflush(stderr);
my_write_core(sig);
}
#endif