Blame


1 fd04aace 2003-11-23 devnull #include <u.h>
2 fd04aace 2003-11-23 devnull #include <libc.h>
3 b2cfc4e2 2003-09-30 devnull
4 5a8e63b2 2004-02-29 devnull static Waitmsg*
5 03417610 2004-12-27 devnull _wait(int n, char *buf)
6 b2cfc4e2 2003-09-30 devnull {
7 03417610 2004-12-27 devnull int l;
8 03417610 2004-12-27 devnull char *fld[5];
9 b2cfc4e2 2003-09-30 devnull Waitmsg *w;
10 b2cfc4e2 2003-09-30 devnull
11 5a8e63b2 2004-02-29 devnull if(n <= 0)
12 b2cfc4e2 2003-09-30 devnull return nil;
13 b2cfc4e2 2003-09-30 devnull buf[n] = '\0';
14 b2cfc4e2 2003-09-30 devnull if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){
15 b2cfc4e2 2003-09-30 devnull werrstr("couldn't parse wait message");
16 b2cfc4e2 2003-09-30 devnull return nil;
17 b2cfc4e2 2003-09-30 devnull }
18 b2cfc4e2 2003-09-30 devnull l = strlen(fld[4])+1;
19 b2cfc4e2 2003-09-30 devnull w = malloc(sizeof(Waitmsg)+l);
20 b2cfc4e2 2003-09-30 devnull if(w == nil)
21 b2cfc4e2 2003-09-30 devnull return nil;
22 b2cfc4e2 2003-09-30 devnull w->pid = atoi(fld[0]);
23 b2cfc4e2 2003-09-30 devnull w->time[0] = atoi(fld[1]);
24 b2cfc4e2 2003-09-30 devnull w->time[1] = atoi(fld[2]);
25 b2cfc4e2 2003-09-30 devnull w->time[2] = atoi(fld[3]);
26 b2cfc4e2 2003-09-30 devnull w->msg = (char*)&w[1];
27 b2cfc4e2 2003-09-30 devnull memmove(w->msg, fld[4], l);
28 b2cfc4e2 2003-09-30 devnull return w;
29 b2cfc4e2 2003-09-30 devnull }
30 b2cfc4e2 2003-09-30 devnull
31 5a8e63b2 2004-02-29 devnull Waitmsg*
32 5a8e63b2 2004-02-29 devnull wait(void)
33 5a8e63b2 2004-02-29 devnull {
34 03417610 2004-12-27 devnull char buf[256];
35 03417610 2004-12-27 devnull
36 03417610 2004-12-27 devnull return _wait(await(buf, sizeof buf-1), buf);
37 5a8e63b2 2004-02-29 devnull }
38 5a8e63b2 2004-02-29 devnull
39 5a8e63b2 2004-02-29 devnull Waitmsg*
40 5a8e63b2 2004-02-29 devnull waitnohang(void)
41 5a8e63b2 2004-02-29 devnull {
42 03417610 2004-12-27 devnull char buf[256];
43 03417610 2004-12-27 devnull
44 03417610 2004-12-27 devnull return _wait(awaitnohang(buf, sizeof buf-1), buf);
45 5a8e63b2 2004-02-29 devnull }
46 5a8e63b2 2004-02-29 devnull
47 03417610 2004-12-27 devnull Waitmsg*
48 03417610 2004-12-27 devnull waitfor(int pid)
49 03417610 2004-12-27 devnull {
50 03417610 2004-12-27 devnull char buf[256];
51 03417610 2004-12-27 devnull
52 03417610 2004-12-27 devnull return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
53 03417610 2004-12-27 devnull }