diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-01-28 07:56:46 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-01-28 07:57:07 -0500 |
commit | e5bb08cc185a28d3e96bfddc7e9a0d837f89b2b8 (patch) | |
tree | 9ff398260021962995dfcab5afbb082f4b23a9ba /common/log.c | |
parent | Merge pull request #480 from crondog/swaylocktrans2 (diff) | |
download | sway-e5bb08cc185a28d3e96bfddc7e9a0d837f89b2b8.tar.gz sway-e5bb08cc185a28d3e96bfddc7e9a0d837f89b2b8.tar.zst sway-e5bb08cc185a28d3e96bfddc7e9a0d837f89b2b8.zip |
Print /proc/<pid>/maps on segfault
Diffstat (limited to 'common/log.c')
-rw-r--r-- | common/log.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/log.c b/common/log.c index f9242bf4..0c0ecf89 100644 --- a/common/log.c +++ b/common/log.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "log.h" | 1 | #include "log.h" |
2 | #include "sway.h" | 2 | #include "sway.h" |
3 | #include "readline.h" | ||
3 | #include <stdarg.h> | 4 | #include <stdarg.h> |
4 | #include <stdio.h> | 5 | #include <stdio.h> |
5 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -142,6 +143,9 @@ void error_handler(int sig) { | |||
142 | void *array[max_lines]; | 143 | void *array[max_lines]; |
143 | char **bt; | 144 | char **bt; |
144 | size_t bt_len; | 145 | size_t bt_len; |
146 | char maps_file[256]; | ||
147 | char maps_buffer[1024]; | ||
148 | FILE *maps; | ||
145 | 149 | ||
146 | sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig); | 150 | sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig); |
147 | bt_len = backtrace(array, max_lines); | 151 | bt_len = backtrace(array, max_lines); |
@@ -155,6 +159,22 @@ void error_handler(int sig) { | |||
155 | for (i = 0; (size_t)i < bt_len; i++) { | 159 | for (i = 0; (size_t)i < bt_len; i++) { |
156 | sway_log(L_ERROR, "Backtrace: %s", bt[i]); | 160 | sway_log(L_ERROR, "Backtrace: %s", bt[i]); |
157 | } | 161 | } |
162 | |||
163 | sway_log(L_ERROR, "Maps:"); | ||
164 | pid_t pid = getpid(); | ||
165 | if (snprintf(maps_file, 255, "/proc/%zd/maps", (size_t)pid) < 255) { | ||
166 | maps = fopen(maps_file, "r"); | ||
167 | while (!feof(maps)) { | ||
168 | char *m = read_line_buffer(maps, maps_buffer, 1024); | ||
169 | if (!m) { | ||
170 | fclose(maps); | ||
171 | sway_log(L_ERROR, "Unable to allocate memory to show maps"); | ||
172 | break; | ||
173 | } | ||
174 | sway_log(L_ERROR, m); | ||
175 | } | ||
176 | fclose(maps); | ||
177 | } | ||
158 | #else | 178 | #else |
159 | sway_log(L_ERROR, "Error: Signal %d.", sig); | 179 | sway_log(L_ERROR, "Error: Signal %d.", sig); |
160 | #endif | 180 | #endif |