sys/ctrace: keep reading on exited process till there is something to read

This commit is contained in:
Giacomo Tesio 2017-11-21 01:32:43 +01:00
parent d9345701c5
commit bdce6c7f9c
1 changed files with 5 additions and 10 deletions

View File

@ -11,7 +11,6 @@ Channel *quit;
Channel *forkc; Channel *forkc;
int readers = 1; int readers = 1;
int output; int output;
int hanging = 0;
typedef struct Msg Msg; typedef struct Msg Msg;
struct Msg { struct Msg {
@ -46,9 +45,9 @@ die(Reader *r)
} }
void void
cwrite(Reader *r, char *cmd) cwrite(Reader *r, char *cmd, int ignore_errors)
{ {
if (write(r->cfd, cmd, strlen(cmd)) < 0) if (write(r->cfd, cmd, strlen(cmd)) < 0 && !ignore_errors)
die(r); die(r);
} }
@ -71,11 +70,8 @@ reader(void *v)
if ((r.tfd = open(s->buf, OREAD)) < 0) if ((r.tfd = open(s->buf, OREAD)) < 0)
die(&r); die(&r);
if(hanging) cwrite(&r, "stop", 0);
cwrite(&r, "waitstop"); cwrite(&r, "startsyscall", 0);
else
cwrite(&r, "stop");
cwrite(&r, "startsyscall");
while(pread(r.tfd, s->buf, sizeof(s->buf)-1, 0) > 0){ while(pread(r.tfd, s->buf, sizeof(s->buf)-1, 0) > 0){
if(strstr(s->buf, " rfork ") != nil){ if(strstr(s->buf, " rfork ") != nil){
@ -97,7 +93,7 @@ reader(void *v)
sendp(out, s); sendp(out, s);
r.msg = s = mallocz(sizeof(Msg), 1); r.msg = s = mallocz(sizeof(Msg), 1);
cwrite(&r, "startsyscall"); cwrite(&r, "startsyscall", 1);
} }
die(&r); die(&r);
} }
@ -202,7 +198,6 @@ ParseArguments:
/* run a command? */ /* run a command? */
if(cmd) { if(cmd) {
hanging = 1;
pid = fork(); pid = fork();
if (pid < 0) if (pid < 0)
sysfatal("fork failed: %r"); sysfatal("fork failed: %r");