From 863b5d814443eb791c2dd07250ac0ae29054adb0 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 4 Feb 2009 20:46:08 -0400 Subject: Added proper handling of SIGINT (C-c) and SIGPIPE (pager quits). --- src/utils.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index 41142624..23ae10c7 100644 --- a/src/utils.h +++ b/src/utils.h @@ -475,6 +475,28 @@ void finish_timer(const char * name); #include "stream.h" #include "pushvar.h" +enum caught_signal_t { + NONE_CAUGHT, + INTERRUPTED, + PIPE_CLOSED +}; + +extern caught_signal_t caught_signal; + +void sigint_handler(int sig); +void sigpipe_handler(int sig); + +inline void check_for_signal() { + switch (caught_signal) { + case NONE_CAUGHT: + break; + case INTERRUPTED: + throw std::runtime_error("Interrupted by user (use Control-D to quit)"); + case PIPE_CLOSED: + throw std::runtime_error("Pipe terminated"); + } +} + /** * @name General utility functions */ -- cgit v1.2.3