Hello,
> 2016/05/21 11:25、Skip Tavakkolian <[email protected]> のメール:
>
> i think this fix is correct; i'm not sure why tokenize didn't have a
> problem walking a buffer it expects to be null terminated.
I agree with skip.
the man wait(2) says:
The underlying system call is await, which fills in the n-
byte buffer s with a textual representation of the pid,
times, and exit string. There is no terminal NUL. The
return value is the length, in bytes, of the data.
thus the typical usage of await is:
Waitmsg*
wait(void)
{
int n, l;
char buf[512], *fld[5];
Waitmsg *w;
n = await(buf, sizeof buf-1);
if(n < 0)
return nil;
buf[n] = '\0';
if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){
werrstr("couldn't parse wait message");
return nil;
}
/sys/src/libc/9sys/dial.c may be fixed as follows:
static int
reap(Dest *dp)
{
char exitsts[2*ERRMAX];
+ int n;
- if (outstandingprocs(dp) && await(exitsts, sizeof exitsts) >= 0) {
+ if (outstandingprocs(dp) && (n = await(exitsts, sizeof exitsts-1)) >=
0) {
+ exitsts[n] = 0;
notedeath(dp, exitsts);
return 0;
}
return -1;
}
probably 2*ERRMAX is enough for await().
I wonder why await() returns non-terminated string?