Dump stack trace on crash also on a file in $HOME
This commit is contained in:
parent
76a68fb071
commit
fa5137cad8
2 changed files with 32 additions and 8 deletions
|
@ -1431,6 +1431,7 @@ on_systray_error:
|
||||||
|
|
||||||
void systray_render_icon(void *t)
|
void systray_render_icon(void *t)
|
||||||
{
|
{
|
||||||
|
abort();
|
||||||
TrayWindow *traywin = t;
|
TrayWindow *traywin = t;
|
||||||
if (systray_profile)
|
if (systray_profile)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
39
src/tint.c
39
src/tint.c
|
@ -31,6 +31,9 @@
|
||||||
#include <X11/extensions/Xdamage.h>
|
#include <X11/extensions/Xdamage.h>
|
||||||
#include <Imlib2.h>
|
#include <Imlib2.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#ifdef HAVE_SN
|
#ifdef HAVE_SN
|
||||||
#include <libsn/sn.h>
|
#include <libsn/sn.h>
|
||||||
|
@ -165,11 +168,31 @@ const char *signal_name(int sig)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log_string(int fd, const char *s)
|
||||||
|
{
|
||||||
|
write_string(2, s);
|
||||||
|
write_string(fd, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_home_dir()
|
||||||
|
{
|
||||||
|
const char *s = getenv("HOME");
|
||||||
|
if (s)
|
||||||
|
return s;
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
if (!pw)
|
||||||
|
return NULL;
|
||||||
|
return pw->pw_dir;
|
||||||
|
}
|
||||||
|
|
||||||
void crash_handler(int sig)
|
void crash_handler(int sig)
|
||||||
{
|
{
|
||||||
write_string(2, "Crashing with signal ");
|
char path[4096];
|
||||||
write_string(2, signal_name(sig));
|
sprintf(path, "%s/.tint2-crash.log", get_home_dir());
|
||||||
write_string(2, "\nBacktrace:\n");
|
int log_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
||||||
|
log_string(log_fd, "Crashing with signal ");
|
||||||
|
log_string(log_fd, signal_name(sig));
|
||||||
|
log_string(log_fd, "\nBacktrace:\n");
|
||||||
|
|
||||||
#ifdef ENABLE_LIBUNWIND
|
#ifdef ENABLE_LIBUNWIND
|
||||||
unw_cursor_t cursor;
|
unw_cursor_t cursor;
|
||||||
|
@ -182,8 +205,8 @@ void crash_handler(int sig)
|
||||||
char fname[128];
|
char fname[128];
|
||||||
fname[0] = '\0';
|
fname[0] = '\0';
|
||||||
(void) unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
|
(void) unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
|
||||||
write_string(2, fname);
|
log_string(log_fd, fname);
|
||||||
write_string(2, "\n");
|
log_string(log_fd, "\n");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef ENABLE_EXECINFO
|
#ifdef ENABLE_EXECINFO
|
||||||
|
@ -193,13 +216,13 @@ void crash_handler(int sig)
|
||||||
char **strings = backtrace_symbols(array, size);
|
char **strings = backtrace_symbols(array, size);
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
write_string(2, strings[i]);
|
log_string(log_fd, strings[i]);
|
||||||
write_string(2, "\n");
|
log_string(log_fd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(strings);
|
free(strings);
|
||||||
#else
|
#else
|
||||||
write_string(2, "Backtrace not supported on this system. Install libunwind or libexecinfo.\n");
|
log_string(log_fd, "Backtrace not supported on this system. Install libunwind or libexecinfo.\n");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
_exit(sig);
|
_exit(sig);
|
||||||
|
|
Loading…
Reference in a new issue