1*68e3ffa3Smatt /* $NetBSD: sigwait.c,v 1.5 2012/03/20 16:26:12 matt Exp $ */
2af3d346aSjdolecek
3af3d346aSjdolecek /*-
4af3d346aSjdolecek * Copyright (c) 2003 The NetBSD Foundation, Inc.
5af3d346aSjdolecek * All rights reserved.
6af3d346aSjdolecek *
7af3d346aSjdolecek * This code is derived from software contributed to The NetBSD Foundation
8af3d346aSjdolecek * by Jaromir Dolecek.
9af3d346aSjdolecek *
10af3d346aSjdolecek * Redistribution and use in source and binary forms, with or without
11af3d346aSjdolecek * modification, are permitted provided that the following conditions
12af3d346aSjdolecek * are met:
13af3d346aSjdolecek * 1. Redistributions of source code must retain the above copyright
14af3d346aSjdolecek * notice, this list of conditions and the following disclaimer.
15af3d346aSjdolecek * 2. Redistributions in binary form must reproduce the above copyright
16af3d346aSjdolecek * notice, this list of conditions and the following disclaimer in the
17af3d346aSjdolecek * documentation and/or other materials provided with the distribution.
18af3d346aSjdolecek *
19af3d346aSjdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20af3d346aSjdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21af3d346aSjdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22af3d346aSjdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23af3d346aSjdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24af3d346aSjdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25af3d346aSjdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26af3d346aSjdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27af3d346aSjdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28af3d346aSjdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29af3d346aSjdolecek * POSSIBILITY OF SUCH DAMAGE.
30af3d346aSjdolecek */
31af3d346aSjdolecek
32af3d346aSjdolecek #include <sys/cdefs.h>
33af3d346aSjdolecek #if defined(LIBC_SCCS) && !defined(lint)
34*68e3ffa3Smatt __RCSID("$NetBSD: sigwait.c,v 1.5 2012/03/20 16:26:12 matt Exp $");
35af3d346aSjdolecek #endif /* LIBC_SCCS and not lint */
36af3d346aSjdolecek
37af3d346aSjdolecek #include "namespace.h"
38af3d346aSjdolecek #include <sys/types.h>
39af3d346aSjdolecek #include <sys/syscall.h>
40af3d346aSjdolecek #include <unistd.h>
41af3d346aSjdolecek #include <signal.h>
425170f004Sdrochner #include <errno.h>
43af3d346aSjdolecek
44af3d346aSjdolecek #ifdef __weak_alias
45af3d346aSjdolecek __weak_alias(sigwait,_sigwait)
46af3d346aSjdolecek #endif
47af3d346aSjdolecek
48*68e3ffa3Smatt int _sigwait(const sigset_t * __restrict, int * __restrict);
49af3d346aSjdolecek
50af3d346aSjdolecek /*
51af3d346aSjdolecek * This is wrapper around sigtimedwait(2), providing sigwait()
52af3d346aSjdolecek * implementation for userland.
53af3d346aSjdolecek */
54af3d346aSjdolecek int
_sigwait(const sigset_t * __restrict set,int * __restrict signum)55af3d346aSjdolecek _sigwait(const sigset_t * __restrict set, int * __restrict signum)
56af3d346aSjdolecek {
575170f004Sdrochner int saved_errno, new_errno, sig;
58af3d346aSjdolecek
595170f004Sdrochner saved_errno = errno;
60690a7f09Sdrochner sig = __sigtimedwait(set, NULL, NULL);
615170f004Sdrochner new_errno = errno;
625170f004Sdrochner errno = saved_errno;
63690a7f09Sdrochner if (sig < 0)
645170f004Sdrochner return (new_errno);
65690a7f09Sdrochner *signum = sig;
66690a7f09Sdrochner return (0);
67af3d346aSjdolecek }
68