Currently, the cleanup() function is never called when the process is
killed. This causes the Emacs plugin to leave the socket file in /tmp. It
would also prevent the terminal colour settings from being restored.
Attached is a patch that fixes this for these signals.
My only concern is with the naming of the "old" variable in the
handler. The two variables, both having "old" in the name is ugly. :-)
Regards,
Elias
Index: src/main.cc
===================================================================
--- src/main.cc (revision 111)
+++ src/main.cc (working copy)
@@ -134,6 +134,34 @@
static struct sigaction new_USR1_action;
//-----------------------------------------------------------------------------
+static struct sigaction old_TERM_action;
+static struct sigaction new_TERM_action;
+
+static void
+signal_TERM_handler(int)
+{
+ struct sigaction old;
+
+ cleanup();
+ sigaction(SIGTERM, &old_TERM_action, &old);
+ raise(SIGTERM);
+}
+
+//-----------------------------------------------------------------------------
+static struct sigaction old_HUP_action;
+static struct sigaction new_HUP_action;
+
+static void
+signal_HUP_handler(int)
+{
+ struct sigaction old;
+
+ cleanup();
+ sigaction(SIGHUP, &old_HUP_action, &old);
+ raise(SIGHUP);
+}
+
+//-----------------------------------------------------------------------------
/**
When APL is started as a script. then several options might be grouped
into a single option. expand_argv() expands such grouped options into
@@ -851,14 +879,20 @@
memset(&new_control_C_action, 0, sizeof(struct sigaction));
memset(&new_USR1_action, 0, sizeof(struct sigaction));
memset(&new_segfault_action, 0, sizeof(struct sigaction));
+ memset(&new_TERM_action, 0, sizeof(struct sigaction));
+ memset(&new_HUP_action, 0, sizeof(struct sigaction));
new_control_C_action.sa_handler = &control_C;
new_USR1_action .sa_handler = &signal_USR1_handler;
new_segfault_action .sa_handler = &seg_fault;
+ new_TERM_action .sa_handler = &signal_TERM_handler;
+ new_HUP_action .sa_handler = &signal_HUP_handler;
sigaction(SIGINT, &new_control_C_action, &old_control_C_action);
sigaction(SIGUSR1, &new_USR1_action, &old_USR1_action);
sigaction(SIGSEGV, &new_segfault_action, &old_segfault_action);
+ sigaction(SIGTERM, &new_TERM_action, &old_TERM_action);
+ sigaction(SIGHUP, &new_HUP_action, &old_HUP_action);
// init NLS so that usage() will be translated
//