Commit dc8e15db authored by Daniel Black's avatar Daniel Black Committed by Sergei Golubchik

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
parent b953bf7e
......@@ -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
......
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