Skip to content

Commit

Permalink
Implement the WCONTINUED flag to the wait(2) family of syscalls and the
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
millert committed Aug 3, 2003
1 parent ea466ed commit 26a45e4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
29 changes: 20 additions & 9 deletions lib/libc/sys/wait.2
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions sys/kern/kern_exit.c
Original file line number Diff line number Diff line change
@@ -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 $ */

/*
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -468,6 +468,18 @@ sys_wait4(q, v, retval)
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);
Expand Down
8 changes: 6 additions & 2 deletions sys/kern/kern_sig.c
Original file line number Diff line number Diff line change
@@ -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 $ */

/*
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions sys/sys/proc.h
Original file line number Diff line number Diff line change
@@ -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 $ */

/*-
Expand Down Expand Up @@ -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) \
Expand Down
7 changes: 5 additions & 2 deletions sys/sys/wait.h
Original file line number Diff line number Diff line change
@@ -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 $ */

/*
Expand Down Expand Up @@ -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)

Expand All @@ -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: */
Expand Down

0 comments on commit 26a45e4

Please sign in to comment.