From 83d2279aaa79ce04aa35b394b5063c6d59ff3ac1 Mon Sep 17 00:00:00 2001 From: Mathias Preiner Date: Tue, 12 Dec 2017 11:34:46 -0800 Subject: [PATCH] Add SIGTERM handler. (#1440) Print statistics if CVC4 gets a SIGTERM signal. --- src/main/util.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/util.cpp b/src/main/util.cpp index 110fc2c67..43c880a7f 100644 --- a/src/main/util.cpp +++ b/src/main/util.cpp @@ -77,6 +77,14 @@ void timeout_handler(int sig, siginfo_t* info, void*) { abort(); } +/** Handler for SIGTERM. */ +void sigterm_handler(int sig, siginfo_t* info, void*) +{ + safe_print(STDERR_FILENO, "CVC4 interrupted by SIGTERM.\n"); + print_statistics(); + abort(); +} + /** Handler for SIGINT, i.e., when the user hits control C. */ void sigint_handler(int sig, siginfo_t* info, void*) { safe_print(STDERR_FILENO, "CVC4 interrupted by user.\n"); @@ -321,6 +329,15 @@ void cvc4_init() throw(Exception) { } #endif /* HAVE_SIGALTSTACK */ + struct sigaction act5; + act5.sa_sigaction = sigterm_handler; + act5.sa_flags = SA_SIGINFO; + sigemptyset(&act5.sa_mask); + if (sigaction(SIGTERM, &act5, NULL)) + { + throw Exception(string("sigaction(SIGTERM) failure: ") + strerror(errno)); + } + #endif /* __WIN32__ */ set_unexpected(cvc4unexpected); -- 2.30.2