From 49abf162fa91397b0c65d41f5c9af31ace4e6290 Mon Sep 17 00:00:00 2001 From: fche Date: Thu, 28 Feb 2008 21:34:46 +0000 Subject: PR5045: clean up after interrupts 2008-02-28 Frank Ch. Eigler PR5045 * session.h (pending_interrupts): New global. * main.cxx (handle_interrupts): New fn to handle SIGINT* etc. * elaborate.cxx, translate.cxx, tapsets.cxx, main.cxx (*): Insert pending_interrupts escape hatches inside potentially timetaking loops. * buildrun.cxx: Don't deal with signals. --- main.cxx | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'main.cxx') diff --git a/main.cxx b/main.cxx index 668c14b8..449c1a2a 100644 --- a/main.cxx +++ b/main.cxx @@ -29,6 +29,7 @@ extern "C" { #include #include +#include #include #include #include @@ -185,6 +186,23 @@ printscript(systemtap_session& s, ostream& o) } } + +int pending_interrupts; + +extern "C" +void handle_interrupt (int /* sig */) +{ + pending_interrupts ++; + if (pending_interrupts > 1) // XXX: should be configurable? time-based? + { + char msg[] = "Too many interrupts received, exiting.\n"; + int rc = write (2, msg, sizeof(msg)-1); + if (rc) /* Do nothing; we don't care if our last gasp went out. */ ; + _exit (1); + } +} + + int main (int argc, char * const argv []) { @@ -541,6 +559,13 @@ main (int argc, char * const argv []) // directory. s.translated_source = string(s.tmpdir) + "/" + s.module_name + ".c"; + // Set up our handler to catch routine signals, to allow clean + // and reasonably timely exit. + signal (SIGHUP, handle_interrupt); + signal (SIGPIPE, handle_interrupt); + signal (SIGINT, handle_interrupt); + signal (SIGTERM, handle_interrupt); + struct tms tms_before; times (& tms_before); struct timeval tv_before; @@ -616,8 +641,10 @@ main (int argc, char * const argv []) for (unsigned j=0; j