summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Woithe <jwoithe@physics.adelaide.edu.au>2009-10-27 08:58:59 +1030
committerKristian Høgsberg <krh@sasori.(none)>2009-11-10 04:14:33 -0500
commitee29be974a3ad011fd6b2a00cea6ef1a710029b7 (patch)
treec44901746110e30d57398788c91ac3e1f4dd25a6
parentfd9ed6c2c040064f86a5b73c757448296a29170f (diff)
Save logs on Ctrl-CHEADmaster
-rw-r--r--nosy-dump.c24
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);