From 2e95929a885dfadecadbf3450234060164483c6f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 13 Feb 2014 11:29:18 +0100 Subject: add basic signal handling --- nullshell.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nullshell.c b/nullshell.c index 52a5a81..9225fd2 100644 --- a/nullshell.c +++ b/nullshell.c @@ -8,14 +8,22 @@ * by Mario A. Valdez-Ramirez (http://www.mariovaldez.net/) */ -#include +#include #include #include +#include +#include #include #include "config.h" #include "version.h" +void sig_callback(int signal) { + printf("\nReceived signal '%s', quitting.\nBye!\n", strsignal(signal)); + + exit(EXIT_SUCCESS); +} + int main(int argc, char **argv) { time_t now; char *ssh_connection, *ssh_client, *ssh_tty; @@ -26,6 +34,10 @@ int main(int argc, char **argv) { ssh_client = getenv("SSH_CLIENT"); ssh_tty = getenv("SSH_TTY"); + /* register signal callbacks */ + signal(SIGTERM, sig_callback); + signal(SIGINT, sig_callback); + /* clear the screen and set cursor to the top left * see 'man 4 console_codes' for details */ fputs("\033[2J\033[1;1H", stdout); -- cgit v1.2.3-54-g00ecf