blob: 31d8c02af7aba63d3944c8837a6c7a3cf5c1ae2e [file] [log] [blame]
rscfd04aac2003-11-23 18:12:54 +00001#include <u.h>
2#include <libc.h>
rscb2cfc4e2003-09-30 17:47:41 +00003
rsc5a8e63b2004-02-29 22:10:26 +00004static Waitmsg*
rsc03417612004-12-27 19:11:21 +00005_wait(int n, char *buf)
rscb2cfc4e2003-09-30 17:47:41 +00006{
rsc03417612004-12-27 19:11:21 +00007 int l;
8 char *fld[5];
rscb2cfc4e2003-09-30 17:47:41 +00009 Waitmsg *w;
10
rsc5a8e63b2004-02-29 22:10:26 +000011 if(n <= 0)
rscb2cfc4e2003-09-30 17:47:41 +000012 return nil;
13 buf[n] = '\0';
14 if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){
15 werrstr("couldn't parse wait message");
16 return nil;
17 }
18 l = strlen(fld[4])+1;
19 w = malloc(sizeof(Waitmsg)+l);
20 if(w == nil)
21 return nil;
22 w->pid = atoi(fld[0]);
23 w->time[0] = atoi(fld[1]);
24 w->time[1] = atoi(fld[2]);
25 w->time[2] = atoi(fld[3]);
26 w->msg = (char*)&w[1];
27 memmove(w->msg, fld[4], l);
28 return w;
29}
30
rsc5a8e63b2004-02-29 22:10:26 +000031Waitmsg*
32wait(void)
33{
rsc03417612004-12-27 19:11:21 +000034 char buf[256];
35
36 return _wait(await(buf, sizeof buf-1), buf);
rsc5a8e63b2004-02-29 22:10:26 +000037}
38
39Waitmsg*
40waitnohang(void)
41{
rsc03417612004-12-27 19:11:21 +000042 char buf[256];
43
44 return _wait(awaitnohang(buf, sizeof buf-1), buf);
45}
46
47Waitmsg*
48waitfor(int pid)
49{
50 char buf[256];
51
52 return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
rsc5a8e63b2004-02-29 22:10:26 +000053}
54