Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: wait.h,v 1.38 2022/08/07 11:06:19 andvar Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1989, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)wait.h	8.2 (Berkeley) 7/10/94
     32  */
     33 
     34 #ifndef _SYS_WAIT_H_
     35 #define _SYS_WAIT_H_
     36 
     37 #include <sys/featuretest.h>
     38 #include <sys/types.h>
     39 #include <sys/sigtypes.h>
     40 #include <sys/siginfo.h>
     41 #include <sys/idtype.h>
     42 
     43 /*
     44  * This file holds definitions relevant to the wait4 system call
     45  * and the alternate interfaces that use it (wait, wait3, waitpid).
     46  */
     47 
     48 /*
     49  * Macros to test the exit status returned by wait
     50  * and extract the relevant values.
     51  */
     52 #if !( defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) ) || defined(_KERNEL)
     53 #define	_W_INT(i)	(i)
     54 #else
     55 #define	_W_INT(w)	(*(int *)(void *)&(w))	/* convert union wait to int */
     56 #endif
     57 
     58 #define	_WSTATUS(x)	(_W_INT(x) & 0177)
     59 #define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */
     60 #define _WCONTINUED	0xffffU
     61 #define WIFSTOPPED(x)	(_WSTATUS(x) == _WSTOPPED && !WIFCONTINUED(x))
     62 #define WIFCONTINUED(x)	(_W_INT(x) == _WCONTINUED)
     63 #define WSTOPSIG(x)	((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
     64 #define WIFSIGNALED(x)	(!WIFSTOPPED(x) && !WIFCONTINUED(x) && !WIFEXITED(x))
     65 #define WTERMSIG(x)	(_WSTATUS(x))
     66 #define WIFEXITED(x)	(_WSTATUS(x) == 0)
     67 #define WEXITSTATUS(x)	((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
     68 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) || defined(_KERNEL)
     69 #define	WCOREFLAG	0200
     70 #define WCOREDUMP(x)	(_W_INT(x) & WCOREFLAG)
     71 
     72 #define	W_EXITCODE(ret, sig)	((unsigned int)(ret) << 8 | (sig))
     73 #define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED)
     74 #define	W_CONTCODE()		(_WCONTINUED)
     75 #endif
     76 
     77 /*
     78  * POSIX option bits for the "options" argument of wait{3,4,6} wait{,p}id:
     79  *
     80  * WNOHANG
     81  *	Causes the wait to not hang if there are no stopped or terminated
     82  *	processes, rather returning an error indication in this case (pid==0).
     83  *
     84  * WSTOPPED/WUNTRACED
     85  *	Indicates that the caller should receive status about untraced
     86  *	children which stop due to signals. If children are stopped
     87  *	and a wait without this option is done, it is as though they
     88  *	were still running, nothing about them is returned.
     89  *
     90  * WCONTINUED
     91  *	Returns information for children that were continued from job
     92  *	control.
     93  *
     94  * WEXITED
     95  *	Is the default for wait/wait3/wait4/waitpid (to report children
     96  *	that have exited), but needs to be explicitly specified for
     97  *	waitid/wait6.
     98  *
     99  * WNOWAIT
    100  *	Returns information about the children without reaping them
    101  *	(changing their status to have been already waited for).
    102  */
    103 #define	WNOHANG		0x00000001	/* don't hang in wait */
    104 #define	WSTOPPED	0x00000002	/* include stopped/untraced children */
    105 #define	WUNTRACED	WSTOPPED	/* the original name for WSTOPPED */
    106 #define	WCONTINUED	0x00000010	/* include continued processes */
    107 #define	WEXITED		0x00000020	/* Wait for exited processes. */
    108 #define	WNOWAIT		0x00010000	/* Don't mark child 'P_WAITED' */
    109 
    110 #if defined(_NETBSD_SOURCE)
    111 #define	WALTSIG		0x00000004	/* wait for processes that exit
    112 					   with an alternate signal (i.e.
    113 					   not SIGCHLD) */
    114 #define	WALLSIG		0x00000008	/* wait for processes that exit
    115 					   with any signal, i.e. SIGCHLD
    116 					   and alternates */
    117 #define	WTRAPPED	0x00000040	/* Wait for a process to hit a trap or
    118 				 	   a breakpoint. */
    119 #define	WNOZOMBIE	0x00020000	/* Ignore zombies */
    120 
    121 /*
    122  * These are the Linux names of some of the above flags, for compatibility
    123  * with Linux's clone(2) API.
    124  */
    125 #define	__WCLONE	WALTSIG
    126 #define	__WALL		WALLSIG
    127 #endif /* _NETBSD_SOURCE */
    128 
    129 #ifdef _KERNEL
    130 #define	WSELECTOPTS	(WEXITED|WUNTRACED|WCONTINUED|WTRAPPED)
    131 #define	WALLOPTS	(WNOHANG|WALTSIG|WALLSIG|WNOWAIT|WNOZOMBIE|WSELECTOPTS)
    132 #endif /* _KERNEL */
    133 
    134 #if defined(_NETBSD_SOURCE) || defined(_XOPEN_SOURCE)
    135 /* POSIX extensions and 4.2/4.3 compatibility: */
    136 
    137 /*
    138  * Tokens for special values of the "pid" parameter to wait4.
    139  */
    140 #define	WAIT_ANY	(-1)	/* any process */
    141 #define	WAIT_MYPGRP	0	/* any process in my process group */
    142 
    143 #include <sys/types.h>
    144 
    145 /*
    146  * Deprecated:
    147  * Structure of the information in the status word returned by wait4.
    148  * If w_stopval==WSTOPPED, then the second structure describes
    149  * the information returned, else the first.
    150  */
    151 union wait {
    152 	int	w_status;		/* used in syscall */
    153 	/*
    154 	 * Terminated process status.
    155 	 */
    156 	struct {
    157 #if BYTE_ORDER == LITTLE_ENDIAN
    158 		unsigned int	w_Termsig:7,	/* termination signal */
    159 				w_Coredump:1,	/* core dump indicator */
    160 				w_Retcode:8,	/* exit code if w_termsig==0 */
    161 				w_Filler:16;	/* upper bits filler */
    162 #endif
    163 #if BYTE_ORDER == BIG_ENDIAN
    164 		unsigned int	w_Filler:16,	/* upper bits filler */
    165 				w_Retcode:8,	/* exit code if w_termsig==0 */
    166 				w_Coredump:1,	/* core dump indicator */
    167 				w_Termsig:7;	/* termination signal */
    168 #endif
    169 	} w_T;
    170 	/*
    171 	 * Stopped process status.  Returned
    172 	 * only for traced children unless requested
    173 	 * with the WUNTRACED option bit.
    174 	 */
    175 	struct {
    176 #if BYTE_ORDER == LITTLE_ENDIAN
    177 		unsigned int	w_Stopval:8,	/* == W_STOPPED if stopped */
    178 				w_Stopsig:8,	/* signal that stopped us */
    179 				w_Filler:16;	/* upper bits filler */
    180 #endif
    181 #if BYTE_ORDER == BIG_ENDIAN
    182 		unsigned int	w_Filler:16,	/* upper bits filler */
    183 				w_Stopsig:8,	/* signal that stopped us */
    184 				w_Stopval:8;	/* == W_STOPPED if stopped */
    185 #endif
    186 	} w_S;
    187 };
    188 #define	w_termsig	w_T.w_Termsig
    189 #define w_coredump	w_T.w_Coredump
    190 #define w_retcode	w_T.w_Retcode
    191 #define w_stopval	w_S.w_Stopval
    192 #define w_stopsig	w_S.w_Stopsig
    193 
    194 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
    195 
    196 #ifndef _KERNEL
    197 #include <sys/cdefs.h>
    198 
    199 __BEGIN_DECLS
    200 struct rusage;	/* forward declaration */
    201 struct wrusage;
    202 
    203 pid_t	wait(int *);
    204 pid_t	waitpid(pid_t, int *, int);
    205 int	waitid(idtype_t, id_t, siginfo_t *, int);
    206 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
    207 #ifndef __LIBC12_SOURCE__
    208 pid_t	wait3(int *, int, struct rusage *) __RENAME(__wait350);
    209 pid_t	wait4(pid_t, int *, int, struct rusage *) __RENAME(__wait450);
    210 pid_t	wait6(idtype_t, id_t, int *, int, struct wrusage *, siginfo_t *);
    211 #endif
    212 #endif
    213 __END_DECLS
    214 #endif
    215 
    216 #endif /* !_SYS_WAIT_H_ */
    217