diff options
-rw-r--r-- | nullshell.c | 14 |
1 files changed, 13 insertions, 1 deletions
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 <time.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> #include <unistd.h> #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); |