summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-08-03 19:25:49 +0000
committermillert <millert@openbsd.org>2003-08-03 19:25:49 +0000
commit26a45e40c64199e50627b576f136ec38eef723cd (patch)
tree51dd2fd4b64ff5568003d355e42a1e3289bcf363
parentprefer fdc to fdce for cache flushing here (diff)
downloadwireguard-openbsd-26a45e40c64199e50627b576f136ec38eef723cd.tar.xz
wireguard-openbsd-26a45e40c64199e50627b576f136ec38eef723cd.zip
Implement the WCONTINUED flag to the wait(2) family of syscalls and the
associated WIFCONTINUED macro as per 1003.1-2001. Adapted from FreeBSD. A minor amount of trickiness is involved here. The value for WCONTINUED is chosen in such a way that _WSTATUS(_WCONTINUED) == _WSTOPPED and the WIFSTOPPED macro has been modified such that WIFSTOPPED(_WCONTINUED) != _WSTOPPED. This means we don't need to add an extra check to the WIFSIGNALED and WIFSTOPPED macros. deraadt@ OK.
-rw-r--r--lib/libc/sys/wait.229
-rw-r--r--sys/kern/kern_exit.c16
-rw-r--r--sys/kern/kern_sig.c8
-rw-r--r--sys/sys/proc.h5
-rw-r--r--sys/sys/wait.h7
5 files changed, 48 insertions, 17 deletions
diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2
index c29be5dfd3d..a0575b0c4cd 100644
--- a/lib/libc/sys/wait.2
+++ b/lib/libc/sys/wait.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: wait.2,v 1.15 2003/06/02 20:18:39 millert Exp $
+.\" $OpenBSD: wait.2,v 1.16 2003/08/03 19:25:49 millert Exp $
.\" $NetBSD: wait.2,v 1.6 1995/02/27 12:39:37 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
@@ -102,18 +102,23 @@ The
.Fa options
parameter contains the bitwise
.Tn OR
-of any of the following options.
-The
-.Dv WNOHANG
-option is used to indicate that the call should not block if
-there are no processes that wish to report status.
-If the
-.Dv WUNTRACED
-option is set, children of the current process that are stopped due to a
+of any of the following options:
+.Bl -tag -width Ds
+.It Dv WCONTINUED
+Causes status to be reported for stopped child processes that have been
+continued by receipt of a
+.Dv SIGCONT
+signal.
+.It Dv WNOHANG
+Indicates that the call should not block if there are no processes that wish
+to report status.
+.It Dv WUNTRACED
+If set, children of the current process that are stopped due to a
.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
or
.Dv SIGSTOP
signal also have their status reported.
+.El
.Pp
If
.Fa rusage
@@ -146,6 +151,12 @@ value of \-1.
The following macros may be used to test the manner of exit of the process.
One of the first three macros will evaluate to a non-zero (true) value:
.Bl -tag -width Ds
+.It Fn WIFCONTINUED status
+True if the process has not terminated, and has continued after a job
+control stop.
+This macro can be true only if the wait call specified the
+.Dv WCONTINUED
+option).
.It Fn WIFEXITED status
True if the process terminated normally by a call to
.Xr _exit 2
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index cc8470af1c5..e7c9f385b24 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.46 2003/07/21 22:44:50 tedu Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.47 2003/08/03 19:25:49 millert Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -397,7 +397,7 @@ sys_wait4(q, v, retval)
if (SCARG(uap, pid) == 0)
SCARG(uap, pid) = -q->p_pgid;
- if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG|WALTSIG))
+ if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG|WALTSIG|WCONTINUED))
return (EINVAL);
loop:
@@ -468,6 +468,18 @@ loop:
error = 0;
return (error);
}
+ if ((SCARG(uap, options) & WCONTINUED) && (p->p_flag & P_CONTINUED)) {
+ p->p_flag &= ~P_CONTINUED;
+ retval[0] = p->p_pid;
+
+ if (SCARG(uap, status)) {
+ status = _WCONTINUED;
+ error = copyout(&status, SCARG(uap, status),
+ sizeof(status));
+ } else
+ error = 0;
+ return (error);
+ }
}
if (nfound == 0)
return (ECHILD);
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 48b2543dd29..f4b4ef03b7f 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.64 2003/07/21 22:44:50 tedu Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.65 2003/08/03 19:25:49 millert Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -818,8 +818,10 @@ psignal(p, signum)
if (prop & SA_CONT)
p->p_siglist &= ~stopsigmask;
- if (prop & SA_STOP)
+ if (prop & SA_STOP) {
p->p_siglist &= ~contsigmask;
+ p->p_flag &= ~P_CONTINUED;
+ }
p->p_siglist |= mask;
@@ -907,6 +909,8 @@ psignal(p, signum)
* an event, then it goes back to run state.
* Otherwise, process goes back to sleep state.
*/
+ p->p_flag |= P_CONTINUED;
+ wakeup(p->p_pptr);
if (action == SIG_DFL)
p->p_siglist &= ~mask;
if (action == SIG_CATCH)
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 222cd322785..0f2c883c272 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.65 2003/06/21 00:42:58 tedu Exp $ */
+/* $OpenBSD: proc.h,v 1.66 2003/08/03 19:25:49 millert Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -255,12 +255,13 @@ struct proc {
#define P_NOZOMBIE 0x100000 /* Pid 1 waits for me instead of dad */
#define P_INEXEC 0x200000 /* Process is doing an exec right now */
#define P_SYSTRACE 0x400000 /* Process system call tracing active*/
+#define P_CONTINUED 0x800000 /* Proc has continued from a stopped state. */
#define P_BITS \
("\20\01ADVLOCK\02CTTY\03INMEM\04NOCLDSTOP\05PPWAIT\06PROFIL\07SELECT" \
"\010SINTR\011SUGID\012SYSTEM\013TIMEOUT\014TRACED\015WAITED\016WEXIT" \
"\017EXEC\020PWEUPC\021FSTRACE\022SSTEP\023SUGIDEXEC\024NOCLDWAIT" \
- "\025NOZOMBIE\026INEXEC\027SYSTRACE")
+ "\025NOZOMBIE\026INEXEC\027SYSTRACE\030CONTINUED")
/* Macro to compute the exit signal to be delivered. */
#define P_EXITSIG(p) \
diff --git a/sys/sys/wait.h b/sys/sys/wait.h
index 34dc801e6f6..71afd1c51cc 100644
--- a/sys/sys/wait.h
+++ b/sys/sys/wait.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: wait.h,v 1.10 2003/06/02 23:28:22 millert Exp $ */
+/* $OpenBSD: wait.h,v 1.11 2003/08/03 19:25:49 millert Exp $ */
/* $NetBSD: wait.h,v 1.11 1996/04/09 20:55:51 cgd Exp $ */
/*
@@ -53,12 +53,14 @@
#define _WSTATUS(x) (_W_INT(x) & 0177)
#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
-#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
+#define _WCONTINUED 0177777 /* process has continued */
+#define WIFSTOPPED(x) ((_W_INT(x) & 0xff) == _WSTOPPED)
#define WSTOPSIG(x) ((_W_INT(x) >> 8) & 0xff)
#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
#define WTERMSIG(x) (_WSTATUS(x))
#define WIFEXITED(x) (_WSTATUS(x) == 0)
#define WEXITSTATUS(x) ((_W_INT(x) >> 8) & 0xff)
+#define WIFCONTINUED(x) ((_W_INT(x) & _WCONTINUED) == _WCONTINUED)
#ifndef _POSIX_SOURCE
#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
@@ -80,6 +82,7 @@
#ifndef _POSIX_SOURCE
#define WALTSIG 4 /* wait for child with alternate exit signal */
#endif
+#define WCONTINUED 8 /* report a job control continued process */
#ifndef _POSIX_SOURCE
/* POSIX extensions and 4.2/4.3 compatibility: */