aboutsummaryrefslogtreecommitdiffhomepage
path: root/signal.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 02:16:14 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 02:16:14 -0800
commitc9c2fc5ee346e15e934dd72ed08774d769cfd7a1 (patch)
tree0746962ac6267fcccb25eb6950074450d7bbc47d /signal.cpp
parentb79854ad1aa814d9d35d76a1929b4726fa4bffa5 (diff)
Restore terminal foreground process group on exit
Diffstat (limited to 'signal.cpp')
-rw-r--r--signal.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/signal.cpp b/signal.cpp
index 2c51e9d2..98883bf4 100644
--- a/signal.cpp
+++ b/signal.cpp
@@ -458,6 +458,14 @@ static void handle_hup( int sig, siginfo_t *info, void *context )
}
}
+/** Handle sigterm. The only thing we do is restore the front process ID, then die. */
+static void handle_term( int sig, siginfo_t *info, void *context )
+{
+ restore_term_foreground_process_group();
+ signal(SIGTERM, SIG_DFL);
+ raise(SIGTERM);
+}
+
/**
Interactive mode ^C handler. Respond to int signal by setting
interrupted-flag and stopping all loops and conditionals.
@@ -572,6 +580,15 @@ void signal_set_handlers()
wperror( L"sigaction" );
FATAL_EXIT();
}
+
+ // SIGTERM restores the terminal controlling process before dying
+ act.sa_flags = SA_SIGINFO;
+ act.sa_sigaction= &handle_term;
+ if( sigaction( SIGTERM, &act, 0 ) )
+ {
+ wperror( L"sigaction" );
+ FATAL_EXIT();
+ }
}
else