summaryrefslogtreecommitdiffstats
path: root/wait_pid.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
committermanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
commit69aec538b456402170dc723af417ba5c05389c32 (patch)
treee6f34c543f17c6392447ea337b2e2868212424d1 /wait_pid.c
downloadqmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz
qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2
qmail-69aec538b456402170dc723af417ba5c05389c32.zip
qmail 1.03 import
Diffstat (limited to 'wait_pid.c')
-rw-r--r--wait_pid.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/wait_pid.c b/wait_pid.c
new file mode 100644
index 0000000..d7a7e84
--- /dev/null
+++ b/wait_pid.c
@@ -0,0 +1,39 @@
1#include <sys/types.h>
2#include <sys/wait.h>
3#include "error.h"
4#include "haswaitp.h"
5
6#ifdef HASWAITPID
7
8int wait_pid(wstat,pid) int *wstat; int pid;
9{
10 int r;
11
12 do
13 r = waitpid(pid,wstat,0);
14 while ((r == -1) && (errno == error_intr));
15 return r;
16}
17
18#else
19
20/* XXX untested */
21/* XXX breaks down with more than two children */
22static int oldpid = 0;
23static int oldwstat; /* defined if(oldpid) */
24
25int wait_pid(wstat,pid) int *wstat; int pid;
26{
27 int r;
28
29 if (pid == oldpid) { *wstat = oldwstat; oldpid = 0; return pid; }
30
31 do {
32 r = wait(wstat);
33 if ((r != pid) && (r != -1)) { oldwstat = *wstat; oldpid = r; continue; }
34 }
35 while ((r == -1) && (errno == error_intr));
36 return r;
37}
38
39#endif