Commit 18c2bdda authored by Cedric Roux's avatar Cedric Roux

don't abord if read fails in get_message

it may legitimately happen when the tracee is ctrl+c'ed.
Let's print something though because read may fail for
other reasons. Why not?
parent 1a9d614f
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/socket.h> #include <sys/socket.h>
#define QUIT(x) do { \
printf("T tracer: QUIT: %s\n", x); \
exit(1); \
} while (0)
/* array used to activate/disactivate a log */ /* array used to activate/disactivate a log */
static int T_IDs[T_NUMBER_OF_IDS]; static int T_IDs[T_NUMBER_OF_IDS];
int *T_active = T_IDs; int *T_active = T_IDs;
...@@ -31,15 +36,15 @@ static void get_message(int s) ...@@ -31,15 +36,15 @@ static void get_message(int s)
int id; int id;
int is_on; int is_on;
if (read(s, &t, 1) != 1) abort(); if (read(s, &t, 1) != 1) QUIT("get_message fails");
printf("got mess %d\n", t); printf("got mess %d\n", t);
switch (t) { switch (t) {
case 0: case 0:
/* toggle all those IDs */ /* toggle all those IDs */
/* optimze? (too much syscalls) */ /* optimze? (too much syscalls) */
if (read(s, &l, sizeof(int)) != sizeof(int)) abort(); if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
while (l) { while (l) {
if (read(s, &id, sizeof(int)) != sizeof(int)) abort(); if (read(s, &id, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
T_IDs[id] = 1 - T_IDs[id]; T_IDs[id] = 1 - T_IDs[id];
l--; l--;
} }
...@@ -47,10 +52,11 @@ printf("got mess %d\n", t); ...@@ -47,10 +52,11 @@ printf("got mess %d\n", t);
case 1: case 1:
/* set IDs as given */ /* set IDs as given */
/* optimize? */ /* optimize? */
if (read(s, &l, sizeof(int)) != sizeof(int)) abort(); if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
id = 0; id = 0;
while (l) { while (l) {
if (read(s, &is_on, sizeof(int)) != sizeof(int)) abort(); if (read(s, &is_on, sizeof(int)) != sizeof(int))
QUIT("get_message fails");
T_IDs[id] = is_on; T_IDs[id] = is_on;
id++; id++;
l--; l--;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment