aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/util/test_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/util/test_config.c')
-rw-r--r--test/core/util/test_config.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 30caf4b1ef..84b376ad3e 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -35,6 +35,7 @@
#include <grpc/support/port_platform.h>
#include <grpc/support/log.h>
+#include "src/core/support/string.h"
#include <stdlib.h>
#include <signal.h>
@@ -88,25 +89,43 @@ static void install_crash_handler() {
#include <stdio.h>
#include <string.h>
#include <grpc/support/useful.h>
+#include <errno.h>
static char g_alt_stack[MINSIGSTKSZ];
#define MAX_FRAMES 32
+/* signal safe output */
+static void output_string(const char *string) {
+ size_t len = strlen(string);
+ ssize_t r;
+
+ do {
+ r = write(STDERR_FILENO, string, len);
+ } while (r == -1 && errno == EINTR);
+}
+
+static void output_num(long num) {
+ char buf[GPR_LTOA_MIN_BUFSIZE];
+ gpr_ltoa(num, buf);
+ output_string(buf);
+}
+
static void crash_handler(int signum, siginfo_t *info, void *data) {
void *addrlist[MAX_FRAMES + 1];
int addrlen;
- int i;
- char **symlist;
- fprintf(stderr, "Caught signal %d\n", signum);
+ output_string("\n\n\n*******************************\nCaught signal ");
+ output_num(signum);
+ output_string("\n");
+
addrlen = backtrace(addrlist, GPR_ARRAY_SIZE(addrlist));
- symlist = backtrace_symbols(addrlist, addrlen);
- for (i = 0; i < addrlen; i++) {
- fprintf(stderr, " %s\n", symlist[i]);
+ if (addrlen == 0) {
+ output_string(" no backtrace\n");
+ } else {
+ backtrace_symbols_fd(addrlist, addrlen, STDERR_FILENO);
}
- free(symlist);
raise(signum);
}
@@ -114,6 +133,7 @@ static void crash_handler(int signum, siginfo_t *info, void *data) {
static void install_crash_handler() {
stack_t ss;
struct sigaction sa;
+
memset(&ss, 0, sizeof(ss));
memset(&sa, 0, sizeof(sa));
ss.ss_size = sizeof(g_alt_stack);