don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
--- a/src/console.c Thu May 14 22:57:13 2009 +0300
+++ b/src/console.c Fri May 15 00:05:01 2009 +0300
@@ -10,6 +10,32 @@
#include <signal.h>
#include <assert.h>
+struct console {
+ /** Configuration */
+ struct console_config config;
+
+ /** Input event */
+ struct event *ev;
+
+ /** Callback functions */
+ const struct console_callbacks *callbacks;
+
+ /** Callback context argument */
+ void *cb_arg;
+
+ /** Old SIGINT handler */
+ struct sigaction old_sigint;
+
+ /** Already initialized? */
+ bool initialized;
+
+ /** Set as log output function? */
+ bool log_output;
+
+ /** In the middle of input? */
+ bool have_input;
+};
+
/** The global console state */
static struct console _console;
@@ -73,6 +99,7 @@
(void) sig;
// interrupt the input line
+ // XXX: is this the right function to call?
rl_free_line_state();
// redisplay on new line
@@ -104,7 +131,7 @@
memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = on_sigint;
- sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGINT, &sigact, &console->old_sigint);
// setup readline
rl_callback_handler_install(config->prompt, console_line);
@@ -190,6 +217,9 @@
console->initialized = false;
+ // restore signal handler
+ sigaction(SIGINT, &console->old_sigint, NULL);
+
// remove stored stuff
console->callbacks = console->cb_arg = NULL;
}
--- a/src/console.h Thu May 14 22:57:13 2009 +0300
+++ b/src/console.h Fri May 15 00:05:01 2009 +0300
@@ -16,6 +16,11 @@
#include <stdbool.h>
/**
+ * The console state.
+ */
+struct console;
+
+/**
* Callbacks for event-based actions
*/
struct console_callbacks {
@@ -41,34 +46,6 @@
};
/**
- * The console state.
- *
- * You may replace the callbacks/cb_arg field with a new one at any time, using console_set_callbacks().
- */
-struct console {
- /** Configuration */
- struct console_config config;
-
- /** Input event */
- struct event *ev;
-
- /** Callback functions */
- const struct console_callbacks *callbacks;
-
- /** Callback context argument */
- void *cb_arg;
-
- /** Already initialized? */
- bool initialized;
-
- /** Set as log output function? */
- bool log_output;
-
- /** In the middle of input? */
- bool have_input;
-};
-
-/**
* Initialize the console, setting up the TTY and input handler.
*
* @param console_ptr returned new console struct
--- a/src/nexus.c Thu May 14 22:57:13 2009 +0300
+++ b/src/nexus.c Fri May 15 00:05:01 2009 +0300
@@ -496,7 +496,7 @@
memset(nexus, 0, sizeof(*nexus));
}
-static void on_sigterm (evutil_socket_t sig, short what, void *arg)
+static void on_sig_shutdown (evutil_socket_t sig, short what, void *arg)
{
struct nexus *nexus = arg;
@@ -539,9 +539,11 @@
FATAL_ERROR(&err, "signals_ignore");
// add our SIGTERM handler before console_init()?
- if ((ERROR_CODE(&err) = signals_add(nexus->signals, SIGTERM, on_sigterm, nexus)))
+ if (
+ (ERROR_CODE(&err) = signals_add(nexus->signals, SIGTERM, on_sig_shutdown, nexus))
+ || (ERROR_CODE(&err) = signals_add(nexus->signals, SIGINT, on_sig_shutdown, nexus))
+ )
FATAL_ERROR(&err, "signals_add");
-
// initialize sock module
if (sock_init(nexus->ev_base, &err))