diff options
-rw-r--r-- | nosy-dump.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/nosy-dump.c b/nosy-dump.c index 17c1456..ced4b2a 100644 --- a/nosy-dump.c +++ b/nosy-dump.c @@ -13,6 +13,8 @@ #include <byteswap.h> #include <termios.h> +#include <signal.h> + #include "list.h" #include "nosy-user.h" #include "nosy-dump.h" @@ -30,6 +32,9 @@ static void decode_link_packet(struct link_packet *packet, size_t length, int include_flags, int exclude_flags); +static int run = 1; +sig_t sys_sigint_handler; + static char *option_nosy_device = "/dev/nosy"; static char *option_view = "packet"; static char *option_output = NULL; @@ -114,6 +119,18 @@ static const struct poptOption options[] = { POPT_TABLEEND }; +void +sigint_handler(int signal_num) +{ + if (run == 1) { + run = 0; + /* Allow all Ctrl-C's except the first to interrupt the program in + * the usual way. + */ + signal(SIGINT, SIG_DFL); + } +} + struct subaction * subaction_create(unsigned long *data, size_t length) { @@ -871,6 +888,8 @@ int main(int argc, const char *argv[]) char c; struct pollfd pollfds[2]; + sys_sigint_handler = signal(SIGINT, sigint_handler); + con = poptGetContext(NULL, argc, argv, options, 0); retval = poptGetNextOpt(con); if (retval < -1) { @@ -943,7 +962,7 @@ int main(int argc, const char *argv[]) pollfds[1].fd = STDIN_FILENO; pollfds[1].events = POLLIN; - while (1) { + while (run) { if (input != NULL) { if (fread(&length, sizeof length, 1, input) != 1) return 0; @@ -988,6 +1007,9 @@ int main(int argc, const char *argv[]) else poptPrintUsage(con, stdout, 0); + if (output != NULL) + fclose(output); + close(fd); poptFreeContext(con); |