aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/log.h1
-rw-r--r--sway/log.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/include/log.h b/include/log.h
index 3d77769c..945ad239 100644
--- a/include/log.h
+++ b/include/log.h
@@ -16,6 +16,7 @@ void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__
16void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); 16void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
17void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); 17void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
18bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); 18bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
19void error_handler(int sig);
19 20
20void layout_log(const swayc_t *c, int depth); 21void layout_log(const swayc_t *c, int depth);
21#endif 22#endif
diff --git a/sway/log.c b/sway/log.c
index a7d73d5c..bea30837 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -8,6 +8,7 @@
8#include <signal.h> 8#include <signal.h>
9#include <errno.h> 9#include <errno.h>
10#include <string.h> 10#include <string.h>
11#include <execinfo.h>
11 12
12int colored = 1; 13int colored = 1;
13log_importance_t v = L_SILENT; 14log_importance_t v = L_SILENT;
@@ -30,6 +31,8 @@ void init_log(log_importance_t verbosity) {
30 fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC); 31 fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC);
31 } 32 }
32 } 33 }
34 signal(SIGSEGV, error_handler);
35 signal(SIGABRT, error_handler);
33} 36}
34 37
35void sway_log_colors(int mode) { 38void sway_log_colors(int mode) {
@@ -114,6 +117,28 @@ bool sway_assert(bool condition, const char* format, ...) {
114 return false; 117 return false;
115} 118}
116 119
120void error_handler(int sig) {
121 int i;
122 int max_lines = 20;
123 void *array[max_lines];
124 char **bt;
125 size_t bt_len;
126
127 sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig);
128 bt_len = backtrace(array, max_lines);
129 bt = backtrace_symbols(array, bt_len);
130 if (!bt) {
131 sway_log(L_ERROR, "Could not allocate sufficient memory for backtrace_symbols(), falling back to stderr");
132 backtrace_symbols_fd(array, bt_len, STDERR_FILENO);
133 exit(1);
134 }
135
136 for (i = 0; (size_t)i < bt_len; i++) {
137 sway_log(L_ERROR, "Backtrace: %s", bt[i]);
138 }
139 exit(1);
140}
141
117#include "workspace.h" 142#include "workspace.h"
118 143
119/* XXX:DEBUG:XXX */ 144/* XXX:DEBUG:XXX */