diff options
author | Christian Hesse <mail@eworm.de> | 2014-02-13 11:29:18 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2014-02-13 11:29:18 +0100 |
commit | 2e95929a885dfadecadbf3450234060164483c6f (patch) | |
tree | 83dc9f991909a5ec298a4101e2db5177dbcf0647 | |
parent | ff35eb4e716a68d991007348121c8947ddee4276 (diff) | |
download | nullshell-2e95929a885dfadecadbf3450234060164483c6f.tar.gz nullshell-2e95929a885dfadecadbf3450234060164483c6f.tar.zst |
add basic signal handling
-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); |