xref: /netbsd-src/lib/libc/gen/waitid.c (revision 7ffce30f1b386effba5cb4ef4effeb52108520c6)
1*7ffce30fSchristos /*	$NetBSD: waitid.c,v 1.4 2016/04/06 04:09:10 christos Exp $	*/
2406ebcd6Schristos 
3406ebcd6Schristos /*-
4406ebcd6Schristos  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5406ebcd6Schristos  * All rights reserved.
6406ebcd6Schristos  *
7406ebcd6Schristos  * This code is derived from software contributed to The NetBSD Foundation
8406ebcd6Schristos  * by Christos Zoulas.
9406ebcd6Schristos  *
10406ebcd6Schristos  * Redistribution and use in source and binary forms, with or without
11406ebcd6Schristos  * modification, are permitted provided that the following conditions
12406ebcd6Schristos  * are met:
13406ebcd6Schristos  * 1. Redistributions of source code must retain the above copyright
14406ebcd6Schristos  *    notice, this list of conditions and the following disclaimer.
15406ebcd6Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16406ebcd6Schristos  *    notice, this list of conditions and the following disclaimer in the
17406ebcd6Schristos  *    documentation and/or other materials provided with the distribution.
18406ebcd6Schristos  *
19406ebcd6Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20406ebcd6Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21406ebcd6Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22406ebcd6Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23406ebcd6Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24406ebcd6Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25406ebcd6Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26406ebcd6Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27406ebcd6Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28406ebcd6Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29406ebcd6Schristos  * POSSIBILITY OF SUCH DAMAGE.
30406ebcd6Schristos  */
31406ebcd6Schristos #include <sys/cdefs.h>
32*7ffce30fSchristos __RCSID("$NetBSD: waitid.c,v 1.4 2016/04/06 04:09:10 christos Exp $");
33406ebcd6Schristos 
34406ebcd6Schristos #include "namespace.h"
35406ebcd6Schristos #include <sys/types.h>
36406ebcd6Schristos #include <sys/time.h>
37406ebcd6Schristos #include <sys/wait.h>
38406ebcd6Schristos #include <sys/resource.h>
39406ebcd6Schristos 
40406ebcd6Schristos #include <string.h>
41406ebcd6Schristos #include <signal.h>
42406ebcd6Schristos 
43406ebcd6Schristos #ifdef __weak_alias
__weak_alias(waitid,_waitid)44406ebcd6Schristos __weak_alias(waitid,_waitid)
45406ebcd6Schristos #endif
46406ebcd6Schristos 
47406ebcd6Schristos int
48406ebcd6Schristos waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
49406ebcd6Schristos {
50406ebcd6Schristos 	int status;
51406ebcd6Schristos 
52eb687c98Schristos 	switch (wait6(idtype, id, &status, flags, NULL, info)) {
53eb687c98Schristos 	case -1:
54eb687c98Schristos 		return -1;
55eb687c98Schristos 	case 0:
56eb687c98Schristos 		if (info != NULL)
57406ebcd6Schristos 			memset(info, 0, sizeof(*info));
58eb687c98Schristos 		/*FALLTHROUGH*/
59eb687c98Schristos 	default:
60406ebcd6Schristos 		return 0;
61406ebcd6Schristos 	}
62eb687c98Schristos }
63