Skip to content
Snippets Groups Projects
Commit 1a6c20cf authored by Cédric Roux's avatar Cédric Roux
Browse files

bugfix: record.c did not manage ctrl+c and ctrl+z correctly

ctrl+c did not work when the program was not connected yet.
It also didn't work if no event was received.
parent 832ecfb4
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,13 @@ void usage(void) ...@@ -30,9 +30,13 @@ void usage(void)
volatile int run = 1; volatile int run = 1;
static int socket = -1;
void force_stop(int x) void force_stop(int x)
{ {
printf("\ngently quit...\n"); printf("\ngently quit...\n");
close(socket);
socket = -1;
run = 0; run = 0;
} }
...@@ -47,7 +51,6 @@ int main(int n, char **v) ...@@ -47,7 +51,6 @@ int main(int n, char **v)
char **on_off_name; char **on_off_name;
int *on_off_action; int *on_off_action;
int on_off_n = 0; int on_off_n = 0;
int socket;
int *is_on; int *is_on;
int number_of_events; int number_of_events;
int i; int i;
...@@ -56,11 +59,6 @@ int main(int n, char **v) ...@@ -56,11 +59,6 @@ int main(int n, char **v)
/* write on a socket fails if the other end is closed and we get SIGPIPE */ /* write on a socket fails if the other end is closed and we get SIGPIPE */
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort(); if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort();
/* exit on ctrl+c and ctrl+z */
if (signal(SIGQUIT, force_stop) == SIG_ERR) abort();
if (signal(SIGINT, force_stop) == SIG_ERR) abort();
if (signal(SIGTSTP, force_stop) == SIG_ERR) abort();
on_off_name = malloc(n * sizeof(char *)); if (on_off_name == NULL) abort(); on_off_name = malloc(n * sizeof(char *)); if (on_off_name == NULL) abort();
on_off_action = malloc(n * sizeof(int)); if (on_off_action == NULL) abort(); on_off_action = malloc(n * sizeof(int)); if (on_off_action == NULL) abort();
...@@ -119,6 +117,11 @@ int main(int n, char **v) ...@@ -119,6 +117,11 @@ int main(int n, char **v)
exit(1); exit(1);
} }
/* exit on ctrl+c and ctrl+z */
if (signal(SIGQUIT, force_stop) == SIG_ERR) abort();
if (signal(SIGINT, force_stop) == SIG_ERR) abort();
if (signal(SIGTSTP, force_stop) == SIG_ERR) abort();
/* read messages */ /* read messages */
while (run) { while (run) {
int type; int type;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment