* console-client/console.c: Include signal.h. (signal_handler): New function. (main): Register signal_handler to trap SIGTERM. ---
Hi, I've been fiddling with running the console client as a system service so it can be started and stopped with, e.g., "deco stop console" or "service console start". Could it have a signal handler added so the client exits cleanly on the SIGTERM from these stop commands? It seems to lock up the display without this. Thanks. David console-client/console.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/console-client/console.c b/console-client/console.c index 2fa0533..4035ebf 100644 --- a/console-client/console.c +++ b/console-client/console.c @@ -18,6 +18,7 @@ #include <argp.h> #include <errno.h> +#include <signal.h> #include <stdio.h> #include <unistd.h> #include <string.h> @@ -290,6 +291,14 @@ console_exit (void) exit (0); } +/* Exit the console client on SIGTERM. */ +static void +signal_handler (int signum) +{ + if (signum == SIGTERM) + console_exit (); +} + /* Signal an error to the user. */ void console_error (const wchar_t *const err_msg) { @@ -744,6 +753,9 @@ main (int argc, char *argv[]) if (console_node) console_setup_node (console_node); + if (signal (SIGTERM, signal_handler) == SIG_ERR) + daemon_error (1, errno, "Could not register a SIGTERM handler"); + #if HAVE_DAEMON if (daemonize) /* Signal parent that all went well. */ -- 1.9.3