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.
This commit is contained in:
Alexandre Duret-Lutz 2015-06-01 15:32:00 +02:00
parent 83364c636f
commit eabed370bf
2 changed files with 33 additions and 1 deletions

View file

@ -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])

View file

@ -21,6 +21,9 @@
#include "argp.h"
#include <cstdlib>
#include <iostream>
#include <signal.h>
#include <sys/wait.h>
#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();
}