aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile4
-rw-r--r--src/abort_handler.c21
-rw-r--r--src/benchmark.py9
-rw-r--r--src/exec.c1
-rw-r--r--src/sig_handlers.c36
5 files changed, 40 insertions, 31 deletions
diff --git a/src/Makefile b/src/Makefile
index b0584b1..79d9f8c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,7 +13,7 @@ LDFLAGS ?= -pthread -static-libgcc
MEMSIZE_KB=$(shell free -t | tail -1 | tr -s ' ' | cut -d ' ' -f 2)
MEMSIZE=$(shell echo $(MEMSIZE_KB)"* 1024" | bc)
-TOOLS = print_status_on_exit.so exec abort_handler.so
+TOOLS = print_status_on_exit.so exec sig_handlers.so
ALLOCS = chattymalloc.so bumpptr_alloc.so speedymalloc.so
TARGETS = $(addprefix $(OBJDIR)/allocators/,$(ALLOCS)) $(addprefix $(OBJDIR)/,$(TOOLS))
@@ -37,7 +37,7 @@ $(OBJDIR)/print_status_on_exit.so: print_status_on_exit.c Makefile
@if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
$(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $<
-$(OBJDIR)/abort_handler.so: abort_handler.c Makefile
+$(OBJDIR)/sig_handlers.so: sig_handlers.c Makefile
@if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
$(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $<
diff --git a/src/abort_handler.c b/src/abort_handler.c
deleted file mode 100644
index 8347f3a..0000000
--- a/src/abort_handler.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static void abort_handler(__attribute__((unused)) int signo) {
- fopen("aborted", "w");
-}
-
-static void __attribute__((constructor)) register_abort_handler(void)
-{
- struct sigaction sa;
- sa.sa_handler = abort_handler;
- sigemptyset(&sa.sa_mask);
-
- if (sigaction(SIGABRT, &sa, NULL) == -1) {
- perror("sigaction");
- exit(1);
- }
-}
-
diff --git a/src/benchmark.py b/src/benchmark.py
index f2aa8a3..4dfaa78 100644
--- a/src/benchmark.py
+++ b/src/benchmark.py
@@ -345,7 +345,7 @@ class Benchmark:
env = dict(os.environ)
env["LD_PRELOAD"] = env.get("LD_PRELOAD", "")
env["LD_PRELOAD"] += " " + f"{src.globalvars.builddir}/print_status_on_exit.so"
- env["LD_PRELOAD"] += " " + f"{src.globalvars.builddir}/abort_handler.so"
+ env["LD_PRELOAD"] += " " + f"{src.globalvars.builddir}/sig_handlers.so"
env["LD_PRELOAD"] += " " + alloc["LD_PRELOAD"]
if "LD_LIBRARY_PATH" in alloc:
@@ -407,10 +407,7 @@ class Benchmark:
result = {}
- if any([res.returncode != 0,
- "ERROR: ld.so" in res.stderr,
- "Segmentation fault" in res.stderr,
- os.path.exists("aborted")]):
+ if res.returncode != 0 or "ERROR: ld.so" in res.stderr:
print()
print_debug("Stdout:\n" + res.stdout)
print_debug("Stderr:\n" + res.stderr)
@@ -418,8 +415,6 @@ class Benchmark:
print_error("{} failed with exit code {} for {}".format(argv, res.returncode, alloc_name))
elif "ERROR: ld.so" in res.stderr:
print_error("Preloading of {} failed for {}".format(alloc["LD_PRELOAD"], alloc_name))
- elif os.path.exists("aborted"):
- os.remove("aborted")
# parse and store results
else:
diff --git a/src/exec.c b/src/exec.c
index 4397992..6985fb2 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -26,7 +26,6 @@ int main(int argc, char* argv[]) {
}
}
-
// Run cmd.
execvp(argv[i], &argv[i]);
diff --git a/src/sig_handlers.c b/src/sig_handlers.c
new file mode 100644
index 0000000..601e454
--- /dev/null
+++ b/src/sig_handlers.c
@@ -0,0 +1,36 @@
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void abnormal_termination_handler(int signo) {
+ exit(signo);
+}
+
+static void __attribute__((constructor)) register_handlers(void)
+{
+ struct sigaction sa, old_sa;
+ sa.sa_handler = abnormal_termination_handler;
+ sigemptyset(&sa.sa_mask);
+
+ sigaction(SIGABRT, NULL, &old_sa);
+ if (old_sa.sa_handler == SIG_DFL) {
+ if (sigaction(SIGABRT, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "SIGABRT handler already set");
+ }
+
+ sigaction(SIGSEGV, NULL, &old_sa);
+ if (old_sa.sa_handler == SIG_DFL) {
+ if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "SIGSEGV handler already set");
+ }
+}
+