tadd awaitfor and waitfor - plan9port - [fork] Plan 9 from user space | |
git clone git://src.adamsgaard.dk/plan9port | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 03417610742c4a67bb0345a8fa0fb4e13dee07f7 | |
parent 955a2ca78d7efc2787864e38a3d902df16fc2541 | |
Author: rsc <devnull@localhost> | |
Date: Mon, 27 Dec 2004 19:11:21 +0000 | |
add awaitfor and waitfor | |
Diffstat: | |
M include/libc.h | 3 +++ | |
M src/lib9/await.c | 14 ++++++++++---- | |
M src/lib9/wait.c | 23 +++++++++++++++++------ | |
3 files changed, 30 insertions(+), 10 deletions(-) | |
--- | |
diff --git a/include/libc.h b/include/libc.h | |
t@@ -693,6 +693,7 @@ extern void abort(void); | |
/* extern int access(char*, int); */ | |
extern long p9alarm(ulong); | |
extern int await(char*, int); | |
+extern int awaitfor(int, char*, int); | |
extern int awaitnohang(char*, int); | |
/* extern int bind(char*, char*, int); give up */ | |
/* extern int brk(void*); <unistd.h> */ | |
t@@ -746,6 +747,7 @@ extern int segfree(void*, ulong); | |
extern int p9sleep(long); | |
/* extern int stat(char*, uchar*, int); give up */ | |
extern Waitmsg* p9wait(void); | |
+extern Waitmsg* p9waitfor(int); | |
extern Waitmsg* waitnohang(void); | |
extern int p9waitpid(void); | |
/* <unistd.h> | |
t@@ -770,6 +772,7 @@ extern ulong rendezvous(ulong, ulong); | |
#undef open | |
#define open p9open | |
#define pipe p9pipe | |
+#define waitfor p9waitfor | |
#endif | |
extern Dir* dirstat(char*); | |
diff --git a/src/lib9/await.c b/src/lib9/await.c | |
t@@ -74,7 +74,7 @@ _p9strsig(char *s) | |
} | |
static int | |
-_await(char *str, int n, int opt) | |
+_await(int pid4, char *str, int n, int opt) | |
{ | |
int pid, status, cd; | |
struct rusage ru; | |
t@@ -82,7 +82,7 @@ _await(char *str, int n, int opt) | |
ulong u, s; | |
for(;;){ | |
- pid = wait3(&status, opt, &ru); | |
+ pid = wait4(pid4, &status, opt, &ru); | |
if(pid <= 0) | |
return -1; | |
u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000); | |
t@@ -108,12 +108,18 @@ _await(char *str, int n, int opt) | |
int | |
await(char *str, int n) | |
{ | |
- return _await(str, n, 0); | |
+ return _await(-1, str, n, 0); | |
} | |
int | |
awaitnohang(char *str, int n) | |
{ | |
- return _await(str, n, WNOHANG); | |
+ return _await(-1, str, n, WNOHANG); | |
+} | |
+ | |
+int | |
+awaitfor(int pid, char *str, int n) | |
+{ | |
+ return _await(pid, str, n, 0); | |
} | |
diff --git a/src/lib9/wait.c b/src/lib9/wait.c | |
t@@ -2,13 +2,12 @@ | |
#include <libc.h> | |
static Waitmsg* | |
-_wait(int nohang) | |
+_wait(int n, char *buf) | |
{ | |
- int n, l; | |
- char buf[512], *fld[5]; | |
+ int l; | |
+ char *fld[5]; | |
Waitmsg *w; | |
- n = (nohang ? awaitnohang : await)(buf, sizeof buf-1); | |
if(n <= 0) | |
return nil; | |
buf[n] = '\0'; | |
t@@ -32,12 +31,24 @@ _wait(int nohang) | |
Waitmsg* | |
wait(void) | |
{ | |
- return _wait(0); | |
+ char buf[256]; | |
+ | |
+ return _wait(await(buf, sizeof buf-1), buf); | |
} | |
Waitmsg* | |
waitnohang(void) | |
{ | |
- return _wait(1); | |
+ char buf[256]; | |
+ | |
+ return _wait(awaitnohang(buf, sizeof buf-1), buf); | |
+} | |
+ | |
+Waitmsg* | |
+waitfor(int pid) | |
+{ | |
+ char buf[256]; | |
+ | |
+ return _wait(awaitfor(pid, buf, sizeof buf-1), buf); | |
} | |