add awaitfor and waitfor

This commit is contained in:
rsc 2004-12-27 19:11:21 +00:00
parent 955a2ca78d
commit 0341761074
3 changed files with 30 additions and 10 deletions

View file

@ -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> */
@ -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>
@ -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*);

View file

@ -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;
@ -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);
@ -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);
}

View file

@ -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';
@ -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);
}