aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--bt.c28
2 files changed, 15 insertions, 17 deletions
diff --git a/README.md b/README.md
index f6a0497..2e691d1 100644
--- a/README.md
+++ b/README.md
@@ -31,8 +31,8 @@ cc -o libbt.so bt.c -shared -fPIC -ldl
cc -o raise1 example/raise1.c -rdynamic
LD_PRELOAD=./libbt.so ./raise1
-[INFO:BT]: installed signal handler
-[INFO:BT]: caught signal 11
+[BT:INFO]: installed signal handler
+[BT:INFO]: caught signal 11
# 0 [ 0x7f53b9e203f4] /usr/lib/libc.so.6+0x963f4
# 1 [ 0x7f53b9dc7120] gsignal+0x20 /usr/lib/libc.so.6+0x3d100
# 2 [ 0x55748166c147] foo+0xe raise1+0x1139
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;