cmds: fix rfork handling in sys/ctrace

This commit is contained in:
Giacomo Tesio 2017-11-17 00:45:15 +01:00
parent fc2e066ca0
commit fd30599a90
1 changed files with 11 additions and 22 deletions

View File

@ -53,9 +53,10 @@ cwrite(Reader *r, char *cmd)
void void
reader(void *v) reader(void *v)
{ {
int forking = 0, newpid; int newpid;
Reader r; Reader r;
Msg *s; Msg *s;
char *rf, *a[16];
r.pid = (int)(uintptr)v; r.pid = (int)(uintptr)v;
r.tfd = r.cfd = -1; r.tfd = r.cfd = -1;
@ -72,31 +73,19 @@ reader(void *v)
cwrite(&r, "startsyscall"); 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 (forking && s->buf[1] == '=' && s->buf[3] != '-') { if(strstr(s->buf, " rfork ") != nil){
forking = 0;
newpid = strtol(&s->buf[3], 0, 0);
sendp(forkc, (void*)(uintptr_t)newpid);
procrfork(reader, (void*)(uintptr_t)newpid, Stacksize, 0);
}
/*
* There are three tests here and they (I hope) guarantee
* no false positives.
*/
if (strstr(s->buf, " Rfork") != nil) {
char *a[8];
char *rf;
rf = strdup(s->buf); rf = strdup(s->buf);
if (tokenize(rf, a, 8) == 5) { if(tokenize(rf, a, 9) == 9
unsigned long flags; && a[4][0] == '<'
&& a[5][0] != '-'
flags = strtoul(a[4], 0, 16); && strcmp(a[2], "rfork") == 0) {
if (flags & RFPROC) newpid = strtol(a[5], 0, 0);
forking = 1; sendp(forkc, (void*)(uintptr_t)newpid);
procrfork(reader, (void*)(uintptr_t)newpid, Stacksize, 0);
} }
free(rf); free(rf);
} }
s->pid = r.pid; s->pid = r.pid;
sendp(out, s); sendp(out, s);