diff options
| author | rsc <devnull@localhost> | 2007-03-26 14:26:32 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2007-03-26 14:26:32 +0000 |
| commit | 4b241872ef56389e6bcf4ab602cd52989cf3151d (patch) | |
| tree | 7e67401e9602ecf338b70a47d4735cddaa1819fe /src/cmd/rc/plan9ish.c | |
| parent | bd1b0cc17e58f8135fa0888cdb2d4fac61f85bce (diff) | |
| download | plan9port-4b241872ef56389e6bcf4ab602cd52989cf3151d.tar.gz plan9port-4b241872ef56389e6bcf4ab602cd52989cf3151d.zip | |
fix wait
Diffstat (limited to 'src/cmd/rc/plan9ish.c')
| -rw-r--r-- | src/cmd/rc/plan9ish.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/cmd/rc/plan9ish.c b/src/cmd/rc/plan9ish.c index 1e896536..da9d8679 100644 --- a/src/cmd/rc/plan9ish.c +++ b/src/cmd/rc/plan9ish.c @@ -199,7 +199,10 @@ int Waitfor(int pid, int unused0){ Waitmsg *w; char errbuf[ERRMAX]; + if(pid >= 0 && !havewaitpid(pid)) + return 0; while((w = wait()) != nil){ + delwaitpid(w->pid); if(w->pid==pid){ if(strncmp(w->msg, "signal: ", 8) == 0) fprint(mapfd(2), "%d: %s\n", w->pid, w->msg); @@ -217,7 +220,7 @@ int Waitfor(int pid, int unused0){ free(w); } - errstr(errbuf, sizeof errbuf); + rerrstr(errbuf, sizeof errbuf); if(strcmp(errbuf, "interrupted")==0) return -1; return 0; } @@ -559,3 +562,43 @@ exitcode(char *msg) n = 1; return n; } + +int *waitpids; +int nwaitpids; + +void +addwaitpid(int pid) +{ + waitpids = realloc(waitpids, (nwaitpids+1)*sizeof waitpids[0]); + if(waitpids == 0) + panic("Can't realloc %d waitpids", nwaitpids+1); + waitpids[nwaitpids++] = pid; +} + +void +delwaitpid(int pid) +{ + int r, w; + + for(r=w=0; r<nwaitpids; r++) + if(waitpids[r] != pid) + waitpids[w++] = waitpids[r]; + nwaitpids = w; +} + +void +clearwaitpids(void) +{ + nwaitpids = 0; +} + +int +havewaitpid(int pid) +{ + int i; + + for(i=0; i<nwaitpids; i++) + if(waitpids[i] == pid) + return 1; + return 0; +} |
