From ecc15f6022e25ae14b35d3fad2950fbbda159ccd Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Sun, 10 Nov 2019 14:05:34 -0500 Subject: [PATCH] Unify tmate-debug.c with tmate --- tmate-debug.c | 15 ++++++++------- tmate-ssh-server.c | 9 +-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tmate-debug.c b/tmate-debug.c index 2a2b660d..81850284 100644 --- a/tmate-debug.c +++ b/tmate-debug.c @@ -85,15 +85,16 @@ void tmate_print_stack_trace(void) free (strings); } -static void handle_crash(__unused int sig) +static void handle_crash(int sig) { - /* - * XXX we are in a signal handler, we are not allowed to use malloc - * and friends, which is what we do - */ - tmate_info("CRASH, printing stack trace"); + /* TODO send stack trace to server */ + const char *what = sig == SIGSEGV ? "SIGSEGV" : "SIGABRT"; + tmate_info("%s printing stack trace", what); tmate_print_stack_trace(); - tmate_fatal("CRASHED"); + + /* Reraise */ + signal(sig, NULL); + kill(getpid(), sig); } void tmate_catch_sigsegv(void) diff --git a/tmate-ssh-server.c b/tmate-ssh-server.c index d9879fda..7f800b73 100644 --- a/tmate-ssh-server.c +++ b/tmate-ssh-server.c @@ -442,13 +442,6 @@ static void handle_sigchld(__unused int sig) } } -static void handle_sigsegv(__unused int sig) -{ - tmate_info("CRASH, printing stack trace"); - tmate_print_stack_trace(); - tmate_fatal("CRASHED"); -} - void tmate_ssh_server_main(struct tmate_session *session, const char *keys_dir, const char *bind_addr, int port) { @@ -457,7 +450,7 @@ void tmate_ssh_server_main(struct tmate_session *session, const char *keys_dir, pid_t pid; int fd; - signal(SIGSEGV, handle_sigsegv); + tmate_catch_sigsegv(); signal(SIGCHLD, handle_sigchld); bind = prepare_ssh(keys_dir, bind_addr, port);