From eabed370bf9cad9833059f1dfcc7fd5074044a6d Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Mon, 1 Jun 2015 15:32:00 +0200 Subject: [PATCH] bin: clear temporary files on termination signals This is particularly important for src/tests/satmin.test, where ltl2tgba might be killed while writing a huge temporary file used for SAT-based minimization. Before this patch, the temporary files would remain in src/tests/satmin.dir/, easily overflowing the 100GB limit of the docker containers we use on the build farm. * src/bin/common_setup.cc: Catch termination signals for all tools, even those that do not yet clear temporary files. * configure.ac: Check for sigaction. --- configure.ac | 2 +- src/bin/common_setup.cc | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9b54b2ee7..4e83efe97 100644 --- a/configure.ac +++ b/configure.ac @@ -104,7 +104,7 @@ fi AX_CHECK_BUDDY AC_CHECK_HEADERS([sys/times.h]) -AC_CHECK_FUNCS([times kill alarm]) +AC_CHECK_FUNCS([times kill alarm sigaction]) LT_CONFIG_LTDL_DIR([ltdl]) LT_INIT([win32-dll]) diff --git a/src/bin/common_setup.cc b/src/bin/common_setup.cc index 10b2f39eb..e45f18271 100644 --- a/src/bin/common_setup.cc +++ b/src/bin/common_setup.cc @@ -21,6 +21,9 @@ #include "argp.h" #include #include +#include +#include +#include "misc/tmpfile.hh" const char* argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; @@ -37,6 +40,33 @@ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n", stream); } +#ifdef HAVE_SIGACTION +static void sig_handler(int sig) +{ + spot::cleanup_tmpfiles(); + // Send the signal again, this time to the default handler, so that + // we return a meaningful error code. + raise(sig); +} + +static void setup_sig_handler() +{ + struct sigaction sa; + sa.sa_handler = sig_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESETHAND; + // Catch termination signals, so we can cleanup temporary files. + sigaction(SIGALRM, &sa, 0); + sigaction(SIGHUP, &sa, 0); + sigaction(SIGINT, &sa, 0); + sigaction(SIGPIPE, &sa, 0); + sigaction(SIGQUIT, &sa, 0); + sigaction(SIGTERM, &sa, 0); +} +#else +# define setup_sig_handler() while (0); +#endif + void setup(char** argv) { @@ -50,6 +80,8 @@ setup(char** argv) argp_err_exit_status = 2; std::ios_base::sync_with_stdio(false); + + setup_sig_handler(); }