Module Name: src
Committed By: christos
Date: Sun Apr 3 00:19:42 UTC 2016
Modified Files:
src/lib/libc: shlib_version
src/lib/libc/gen: Makefile.inc
src/lib/libc/include: namespace.h
src/lib/libc/sys: Makefile.inc wait.2
Added Files:
src/lib/libc/gen: waitid.c
Log Message:
userland bits for wait6/waitid.
To generate a diff of this commit:
cvs rdiff -u -r1.262 -r1.263 src/lib/libc/shlib_version
cvs rdiff -u -r1.193 -r1.194 src/lib/libc/gen/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/gen/waitid.c
cvs rdiff -u -r1.179 -r1.180 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.228 -r1.229 src/lib/libc/sys/Makefile.inc
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/sys/wait.2
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/shlib_version
diff -u src/lib/libc/shlib_version:1.262 src/lib/libc/shlib_version:1.263
--- src/lib/libc/shlib_version:1.262 Thu Jan 14 15:42:29 2016
+++ src/lib/libc/shlib_version Sat Apr 2 20:19:42 2016
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.262 2016/01/14 20:42:29 christos Exp $
+# $NetBSD: shlib_version,v 1.263 2016/04/03 00:19:42 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@@ -44,4 +44,4 @@
# - decide whether soft-float should support fenv.h, including thread-local contett
# - stop all math functions from setting errno
major=12
-minor=200
+minor=201
Index: src/lib/libc/gen/Makefile.inc
diff -u src/lib/libc/gen/Makefile.inc:1.193 src/lib/libc/gen/Makefile.inc:1.194
--- src/lib/libc/gen/Makefile.inc:1.193 Thu Jan 14 15:41:23 2016
+++ src/lib/libc/gen/Makefile.inc Sat Apr 2 20:19:42 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.193 2016/01/14 20:41:23 christos Exp $
+# $NetBSD: Makefile.inc,v 1.194 2016/04/03 00:19:42 christos Exp $
# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
# gen sources
@@ -35,8 +35,9 @@ SRCS+= alarm.c alphasort.c arc4random.c
sysctlnametomib.c syslog.c telldir.c time.c \
times.c toascii.c tolower_.c ttyname.c ttyslot.c toupper_.c ualarm.c \
ulimit.c uname.c unvis.c usleep.c utime.c utimens.c utmp.c \
- utmpx.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c warnx.c \
- warnc.c vwarn.c vwarnx.c vwarnc.c verr.c verrx.c verrc.c wordexp.c
+ utmpx.c valloc.c vis.c wait.c wait3.c waitid.c waitpid.c warn.c \
+ warnx.c warnc.c vwarn.c vwarnx.c vwarnc.c verr.c verrx.c verrc.c \
+ wordexp.c
# uses alloca
COPTS.execvp.c = -Wno-stack-protector
Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.179 src/lib/libc/include/namespace.h:1.180
--- src/lib/libc/include/namespace.h:1.179 Thu Sep 10 10:05:06 2015
+++ src/lib/libc/include/namespace.h Sat Apr 2 20:19:42 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.179 2015/09/10 14:05:06 christos Exp $ */
+/* $NetBSD: namespace.h,v 1.180 2016/04/03 00:19:42 christos Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -759,6 +759,7 @@
#define wait _wait
#define wait3 _wait3
#define wait4 _wait4
+#define waitid _waitid
#define waitpid _waitpid
#define wcscasecmp _wcscasecmp
#define wcscasecmp_l _wcscasecmp_l
Index: src/lib/libc/sys/Makefile.inc
diff -u src/lib/libc/sys/Makefile.inc:1.228 src/lib/libc/sys/Makefile.inc:1.229
--- src/lib/libc/sys/Makefile.inc:1.228 Sun Nov 29 01:10:01 2015
+++ src/lib/libc/sys/Makefile.inc Sat Apr 2 20:19:42 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.228 2015/11/29 06:10:01 pgoyette Exp $
+# $NetBSD: Makefile.inc,v 1.229 2016/04/03 00:19:42 christos Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@@ -132,8 +132,8 @@ ASM= access.S acct.S \
__posix_chown.S __posix_fchown.S __posix_lchown.S \
__posix_rename.S profil.S \
__quotactl.S \
- rasctl.S readlinkat.S reboot.S recvfrom.S recvmmsg.S recvmsg.S rename.S \
- renameat.S revoke.S rmdir.S \
+ rasctl.S readlinkat.S reboot.S recvfrom.S recvmmsg.S recvmsg.S \
+ rename.S renameat.S revoke.S rmdir.S \
semconfig.S semget.S semop.S \
sendmmsg.S sendmsg.S sendto.S setegid.S seteuid.S \
setgid.S setgroups.S __setitimer50.S __setlogin.S setpgid.S \
@@ -173,7 +173,7 @@ WEAKASM= accept.S __aio_suspend50.S clos
readv.S _sched_setparam.S _sched_getparam.S _sched_setaffinity.S \
_sched_getaffinity.S sched_yield.S \
__select50.S setcontext.S __sigprocmask14.S __sigsuspend14.S sysarch.S \
- __wait450.S write.S writev.S
+ __wait450.S wait6.S write.S writev.S
NOERR= getegid.S geteuid.S getgid.S getpid.S getppid.S getuid.S \
issetugid.S posix_spawn.S sync.S __posix_fadvise50.S
@@ -373,6 +373,7 @@ MLINKS+=utimes.2 futimes.2 utimes.2 luti
MLINKS+=utimes.2 utimens.2 utimes.2 futimens.2 utimes.2 lutimens.2
MLINKS+=utimes.2 utimensat.2
MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2
+MLINKS+=wait.2 wait6.2 wait.2 waitid.2
MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2
MLINKS+=pipe.2 pipe2.2
MLINKS+=accept.2 paccept.2
Index: src/lib/libc/sys/wait.2
diff -u src/lib/libc/sys/wait.2:1.27 src/lib/libc/sys/wait.2:1.28
--- src/lib/libc/sys/wait.2:1.27 Sat Apr 3 11:43:46 2010
+++ src/lib/libc/sys/wait.2 Sat Apr 2 20:19:42 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: wait.2,v 1.27 2010/04/03 15:43:46 jruoho Exp $
+.\" $NetBSD: wait.2,v 1.28 2016/04/03 00:19:42 christos Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -29,12 +29,14 @@
.\"
.\" @(#)wait.2 8.2 (Berkeley) 4/19/94
.\"
-.Dd April 3, 2010
+.Dd April 2, 2016
.Dt WAIT 2
.Os
.Sh NAME
.Nm wait ,
+.Nm waitid ,
.Nm waitpid ,
+.Nm wait6 ,
.Nm wait4 ,
.Nm wait3
.Nd wait for process termination
@@ -46,11 +48,15 @@
.Fn wait "int *status"
.Ft pid_t
.Fn waitpid "pid_t wpid" "int *status" "int options"
+.Ft int
+.Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options"
.In sys/resource.h
.Ft pid_t
.Fn wait3 "int *status" "int options" "struct rusage *rusage"
.Ft pid_t
.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
+.Ft pid_t
+.Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct __wrusage *wrusage" "siginfo_t *infop"
.Sh DESCRIPTION
The
.Fn wait
@@ -68,12 +74,16 @@ as defined below.
.Pp
The
.Fn wait4
+and
+.Fn wait6
call provides a more general interface for programs
that need to wait for certain child processes,
that need resource utilization statistics accumulated by child processes,
or that require options.
The other wait functions are implemented using
.Fn wait4 .
+or
+.Fn wait6 .
.Pp
The
.Fa wpid
@@ -147,6 +157,305 @@ process and all its
children is returned (this information is currently not available
for stopped processes).
.Pp
+The
+.Fn wait6
+function is the most general function in this family and its distinct
+features are:
+.Pp
+All of the desired process statuses to be waited on must be explicitly
+specified in
+.Fa options .
+The
+.Fn wait ,
+.Fn waitpid ,
+.Fn wait3 ,
+and
+.Fn wait4
+functions all implicitly wait for exited and trapped processes,
+but the
+.Fn waitid
+and
+.Fn wait6
+functions require the corresponding
+.Dv WEXITED
+and
+.Dv WTRAPPED
+flags to be explicitly specified.
+This allows waiting for processes which have experienced other
+status changes without having to also handle the exit status from
+terminated processes.
+.Pp
+The
+.Fn wait6
+function accepts a
+.Fa wrusage
+argument which points to a structure defined as:
+.Bd -literal
+struct wrusage {
+ struct rusage wru_self;
+ struct rusage wru_children;
+};
+.Ed
+.Pp
+This allows the calling process to collect resource usage statistics
+from both its own child process as well as from its grand children.
+When no resource usage statistics are needed this pointer can be
+.Dv NULL .
+.Pp
+The last argument
+.Fa infop
+must be either
+.Dv NULL
+or a pointer to a
+.Fa siginfo_t
+structure.
+If
+.Pf non- Dv NULL ,
+the structure is filled with the same data as for a
+.Dv SIGCHLD
+signal delivered when the process changed state.
+.Pp
+The set of child processes to be queried is specified by the arguments
+.Fa idtype
+and
+.Fa id .
+The separate
+.Fa idtype
+and
+.Fa id
+arguments support many other types of
+identifers in addition to process IDs and process group IDs.
+.Bl -bullet -offset indent
+.It
+If
+.Fa idtype
+is
+.Dv P_PID ,
+.Fn waitid
+and
+.Fn wait6
+wait for the child process with a process ID equal to
+.Dv (pid_t)id .
+.It
+If
+.Fa idtype
+is
+.Dv P_PGID ,
+.Fn waitid
+and
+.Fn wait6
+wait for the child process with a process group ID equal to
+.Dv (pid_t)id .
+.It
+If
+.Fa idtype
+is
+.Dv P_ALL ,
+.Fn waitid
+and
+.Fn wait6
+wait for any child process and the
+.Dv id
+is ignored.
+.It
+If
+.Fa idtype
+is
+.Dv P_PID
+or
+.Dv P_PGID
+and the
+.Dv id
+is zero,
+.Fn waitid
+and
+.Fn wait6
+wait for any child process in the same process group as the caller.
+.El
+.Pp
+Non-standard identifier types supported by this
+implementation of
+.Fn waitid
+and
+.Fn wait6
+are:
+.Bl -tag -width P_JAILID
+.It Dv P_UID
+Wait for processes whose effective user ID is equal to
+.Dv (uid_t) Fa id .
+.It Dv P_GID
+Wait for processes whose effective group ID is equal to
+.Dv (gid_t) Fa id .
+.It Dv P_SID
+Wait for processes whose session ID is equal to
+.Fa id .
+.\" This is just how sessions work, not sure this needs to be documented here
+If the child process started its own session,
+its session ID will be the same as its process ID.
+Otherwise the session ID of a child process will match the caller's session ID.
+.\" .It Dv P_JAILID
+.\" Waits for processes within a jail whose jail identifier is equal to
+.\" .Fa id .
+.El
+.Pp
+For the
+.Fn waitpid
+and
+.Fn wait4
+functions, the single
+.Fa wpid
+argument specifies the set of child processes for which to wait.
+.Bl -bullet -offset indent
+.It
+If
+.Fa wpid
+is -1, the call waits for any child process.
+.It
+If
+.Fa wpid
+is 0,
+the call waits for any child process in the process group of the caller.
+.It
+If
+.Fa wpid
+is greater than zero, the call waits for the process with process ID
+.Fa wpid .
+.It
+If
+.Fa wpid
+is less than -1, the call waits for any process whose process group ID
+equals the absolute value of
+.Fa wpid .
+.El
+.Pp
+The
+.Fa status
+argument is defined below.
+.Pp
+The
+.Fa options
+argument contains the bitwise OR of any of the following options.
+.Bl -tag -width WCONTINUED
+.It Dv WCONTINUED
+Report the status of selected processes that
+have continued from a job control stop by receiving a
+.Dv SIGCONT
+signal.
+.It Dv WNOHANG
+Do not block when
+there are no processes wishing to report status.
+.It Dv WUNTRACED
+Report the status of selected processes which are stopped due to a
+.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
+or
+.Dv SIGSTOP
+signal.
+.It Dv WSTOPPED
+An alias for
+.Dv WUNTRACED .
+.It Dv WTRAPPED
+Report the status of selected processes which are being traced via
+.Xr ptrace 2
+and have trapped or reached a breakpoint.
+This flag is implicitly set for the functions
+.Fn wait ,
+.Fn waitpid ,
+.Fn wait3 ,
+and
+.Fn wait4 .
+.br
+For the
+.Fn waitid
+and
+.Fn wait6
+functions, the flag has to be explicitly included in
+.Fa options
+if status reports from trapped processes are expected.
+.It Dv WEXITED
+Report the status of selected processes which have terminated.
+This flag is implicitly set for the functions
+.Fn wait ,
+.Fn waitpid ,
+.Fn wait3 ,
+and
+.Fn wait4 .
+.br
+For the
+.Fn waitid
+and
+.Fn wait6
+functions, the flag has to be explicitly included in
+.Fa options
+if status reports from terminated processes are expected.
+.It Dv WNOWAIT
+Keep the process whose status is returned in a waitable state.
+The process may be waited for again after this call completes.
+.El
+.sp
+For the
+.Fn waitid
+and
+.Fn wait6
+functions, at least one of the options
+.Dv WEXITED ,
+.Dv WUNTRACED ,
+.Dv WSTOPPED ,
+.Dv WTRAPPED ,
+or
+.Dv WCONTINUED
+must be specified.
+Otherwise there will be no events for the call to report.
+To avoid hanging indefinitely in such a case these functions
+return -1 with
+.Dv errno
+set to
+.Dv EINVAL .
+.Pp
+If
+.Fa rusage
+is non-NULL, a summary of the resources used by the terminated
+process and all its children is returned.
+.Pp
+If
+.Fa wrusage
+is non-NULL, separate summaries are returned for the resources used
+by the terminated process and the resources used by all its children.
+.Pp
+If
+.Fa infop
+is non-NULL, a
+.Dv siginfo_t
+structure is returned with the
+.Fa si_signo
+field set to
+.Dv SIGCHLD
+and the
+.Fa si_pid
+field set to the process ID of the process reporting status.
+For the exited process, the
+.Fa si_status
+field of the
+.Dv siginfo_t
+structure contains the full 32 bit exit status passed to
+.Xr _exit 2 ;
+the
+.Fa status
+argument of other calls only returns 8 lowest bits of the exit status.
+.Pp
+When the
+.Dv WNOHANG
+option is specified and no processes
+wish to report status,
+.Fn waitid
+sets the
+.Fa si_signo
+and
+.Fa si_pid
+fields in
+.Fa infop
+to zero.
+Checking these fields is the only way to know if a status change was reported.
+.Pp
When the
.Dv WNOHANG
option is specified and no processes
@@ -255,6 +564,7 @@ Otherwise, a value of \-1 is returned an
is set to indicate the error.
.Pp
If
+.Fn wait6 ,
.Fn wait4 ,
.Fn wait3
or
@@ -275,12 +585,42 @@ If an error is detected or a caught sign
a value of \-1 is returned and
.Va errno
is set to indicate the error.
+.Pp
+If
+.Fn waitid
+returns because one or more processes have a state change to report,
+0 is returned.
+If an error is detected,
+a value of -1
+is returned and
+.Va errno
+is set to indicate the error.
+If
+.Dv WNOHANG
+is specified and there are
+no stopped, continued or exited children,
+0 is returned.
+The
+.Fa si_signo
+and
+.Fa si_pid
+fields of
+.Fa infop
+must be checked against zero to determine if a process reported status.
.Sh ERRORS
.Fn wait
will fail and return immediately if:
.Bl -tag -width Er
.It Bq Er ECHILD
The calling process has no existing unwaited-for child processes.
+.It Bq Er ECHILD
+No status from the terminated child process is available
+because the calling process has asked the system to discard
+such status by ignoring the signal
+.Dv SIGCHLD
+or setting the flag
+.Dv SA_NOCLDWAIT
+for that signal.
.It Bq Er EFAULT
The
.Fa status
@@ -296,8 +636,10 @@ flag set.
.El
.Pp
In addition,
+.Fn wait6 ,
.Fn wait3 ,
.Fn wait4 ,
+.Fn waitid ,
and
.Fn waitpid
will fail and return immediately if:
@@ -308,7 +650,9 @@ An invalid value was specified for
.El
.Sh SEE ALSO
.Xr _exit 2 ,
-.Xr sigaction 2
+.Xr ptrace 2 ,
+.Xr sigaction 2 ,
+.Xr siginfo 2
.Sh STANDARDS
The
.Fn wait
@@ -317,6 +661,10 @@ and
functions conform to
.St -p1003.1-90 ;
the
+.Fn waitid
+function conforms to
+.St -p1003.1-2004 ;
+the
.Fn wait3
function conforms to
.St -xpg4 ;
Added files:
Index: src/lib/libc/gen/waitid.c
diff -u /dev/null src/lib/libc/gen/waitid.c:1.1
--- /dev/null Sat Apr 2 20:19:42 2016
+++ src/lib/libc/gen/waitid.c Sat Apr 2 20:19:42 2016
@@ -0,0 +1,66 @@
+/* $NetBSD: waitid.c,v 1.1 2016/04/03 00:19:42 christos Exp $ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: waitid.c,v 1.1 2016/04/03 00:19:42 christos Exp $");
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/resource.h>
+
+#include <string.h>
+#include <signal.h>
+
+#ifdef __weak_alias
+__weak_alias(waitpid,_waitpid)
+#endif
+
+#ifdef __weak_alias
+__weak_alias(waitid,_waitid)
+#endif
+
+int
+waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
+{
+ int status;
+ pid_t rv;
+
+ rv = wait6(idtype, id, &status, flags, NULL, info);
+
+ if (rv < 0)
+ return rv;
+
+ if (rv == 0 && info != NULL)
+ memset(info, 0, sizeof(*info));
+
+ return 0;
+}