Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc userland bits for wait6/waitid.



details:   https://anonhg.NetBSD.org/src/rev/c8cc6628e0cb
branches:  trunk
changeset: 814651:c8cc6628e0cb
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Apr 03 00:19:42 2016 +0000

description:
userland bits for wait6/waitid.

diffstat:

 lib/libc/gen/Makefile.inc    |    7 +-
 lib/libc/gen/waitid.c        |   66 ++++++++
 lib/libc/include/namespace.h |    3 +-
 lib/libc/shlib_version       |    4 +-
 lib/libc/sys/Makefile.inc    |    9 +-
 lib/libc/sys/wait.2          |  354 ++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 430 insertions(+), 13 deletions(-)

diffs (truncated from 608 to 300 lines):

diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Sun Apr 03 00:18:01 2016 +0000
+++ b/lib/libc/gen/Makefile.inc Sun Apr 03 00:19:42 2016 +0000
@@ -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 @@
        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
diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/gen/waitid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/waitid.c     Sun Apr 03 00:19:42 2016 +0000
@@ -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;
+}
diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h      Sun Apr 03 00:18:01 2016 +0000
+++ b/lib/libc/include/namespace.h      Sun Apr 03 00:19:42 2016 +0000
@@ -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
diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/shlib_version
--- a/lib/libc/shlib_version    Sun Apr 03 00:18:01 2016 +0000
+++ b/lib/libc/shlib_version    Sun Apr 03 00:19:42 2016 +0000
@@ -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
diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Sun Apr 03 00:18:01 2016 +0000
+++ b/lib/libc/sys/Makefile.inc Sun Apr 03 00:19:42 2016 +0000
@@ -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 @@
                __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 @@
        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 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
diff -r 5cf6f63b7d0c -r c8cc6628e0cb lib/libc/sys/wait.2
--- a/lib/libc/sys/wait.2       Sun Apr 03 00:18:01 2016 +0000
+++ b/lib/libc/sys/wait.2       Sun Apr 03 00:19:42 2016 +0000
@@ -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 @@
 .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 @@
 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



Home | Main Index | Thread Index | Old Index