aboutsummaryrefslogtreecommitdiff
path: root/bt.c
diff options
context:
space:
mode:
Diffstat (limited to 'bt.c')
-rw-r--r--bt.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/bt.c b/bt.c
index 4a2c743..d51d35c 100644
--- a/bt.c
+++ b/bt.c
@@ -33,16 +33,14 @@
#include <unwind.h> // from gcc, clang
-#define LOG(fmt, ...) \
- do { \
- char buf[1024]; \
- int cnt = snprintf(buf, sizeof(buf), fmt "\n", ##__VA_ARGS__); \
- write(STDERR_FILENO, buf, cnt); \
+#define LOG(fmt, ...) \
+ do { \
+ fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
} while (0)
-#define INFO(fmt, ...) LOG("[\e[0;32mINFO:BT\e[0m]: " fmt, ##__VA_ARGS__)
-#define WARN(fmt, ...) LOG("[\e[0;33mWARN:BT\e[0m]: " fmt, ##__VA_ARGS__)
-#define FAIL(fmt, ...) LOG("[\e[0;31mFAIL:BT\e[0m]: " fmt, ##__VA_ARGS__)
+#define INFO(fmt, ...) LOG("[BT:\e[0;32mINFO\e[0m]: " fmt, ##__VA_ARGS__)
+#define WARN(fmt, ...) LOG("[BT:\e[0;33mWARN\e[0m]: " fmt, ##__VA_ARGS__)
+#define FAIL(fmt, ...) LOG("[BT:\e[0;31mFAIL\e[0m]: " fmt, ##__VA_ARGS__)
// -- UNWIND HANDLER -----------------------------------------------------------
@@ -109,16 +107,16 @@ static void libbt_report(int sig, siginfo_t* info, void* ucontext) {
OLD.sa_handler(sig);
}
- const char* noexit = getenv("BT_NOEXIT");
+ const char* noexit = getenv("LIBBT_NOEXIT");
if (noexit && noexit[0] == '1') {
return;
}
- INFO("exit after catching signal, set BT_NOEXIT=1 to keep running");
+ INFO("exit after catching signal, set LIBBT_NOEXIT=1 to keep running");
exit(42);
}
static void* libbt_install_sigstack() {
- const size_t STACK_SIZE = 8192;
+ const size_t STACK_SIZE = 8 * MINSIGSTKSZ;
void* sp = malloc(STACK_SIZE);
if (sp == NULL) {
@@ -149,10 +147,10 @@ static int libbt_install_sighandler() {
// -- THREAD HANDLING ----------------------------------------------------------
-int (*NEXT_PTHREAD_CREATE)(pthread_t*,
- const pthread_attr_t*,
- void* (*)(void*),
- void*);
+static int (*NEXT_PTHREAD_CREATE)(pthread_t*,
+ const pthread_attr_t*,
+ void* (*)(void*),
+ void*);
static int THREAD_CREATE_SIGSTACK = 0;