add POSIX sigtimedwait(), sigwaitinfo(), sigwait() - wait for queued signals

note these are for non-threaded programs only - libpthread will provide
it's own thread-aware wrapper
This commit is contained in:
jdolecek 2003-02-15 21:11:47 +00:00
parent fa2b78c32c
commit af3d346a8c
8 changed files with 393 additions and 7 deletions

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.536 2003/02/13 23:57:53 jmc Exp $
# $NetBSD: mi,v 1.537 2003/02/15 21:11:47 jdolecek Exp $
./usr/bin/addr2line comp-debug-bin
./usr/bin/ar comp-util-bin
./usr/bin/as comp-util-bin
@ -1291,6 +1291,9 @@
./usr/share/man/cat2/sigreturn.0 comp-c-catman
./usr/share/man/cat2/sigstack.0 comp-c-catman
./usr/share/man/cat2/sigsuspend.0 comp-c-catman
./usr/share/man/cat2/sigtimedwait.0 comp-c-catman
./usr/share/man/cat2/sigwait.0 comp-c-catman
./usr/share/man/cat2/sigwaitinfo.0 comp-c-catman
./usr/share/man/cat2/socket.0 comp-c-catman
./usr/share/man/cat2/socketpair.0 comp-c-catman
./usr/share/man/cat2/stat.0 comp-c-catman
@ -4328,6 +4331,9 @@
./usr/share/man/man2/sigreturn.2 comp-c-man
./usr/share/man/man2/sigstack.2 comp-c-man
./usr/share/man/man2/sigsuspend.2 comp-c-man
./usr/share/man/man2/sigtimedwait.2 comp-c-man
./usr/share/man/man2/sigwait.2 comp-c-man
./usr/share/man/man2/sigwaitinfo.2 comp-c-man
./usr/share/man/man2/socket.2 comp-c-man
./usr/share/man/man2/socketpair.2 comp-c-man
./usr/share/man/man2/stat.2 comp-c-man

@ -1,4 +1,4 @@
/* $NetBSD: signal.h,v 1.23 2003/01/18 10:32:11 thorpej Exp $ */
/* $NetBSD: signal.h,v 1.24 2003/02/15 21:11:49 jdolecek Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -170,6 +170,14 @@ int sigignore __P((int));
int sigpause __P((int));
int sigrelse __P((int));
void (*sigset __P((int, void (*)(int)))) __P((int));
int sigwait __P((const sigset_t * __restrict, int * __restrict));
int sigwaitinfo __P((const sigset_t * __restrict, siginfo_t * __restrict));
struct timespec;
int sigtimedwait __P((const sigset_t * __restrict,
siginfo_t * __restrict, const struct timespec * __restrict));
int __sigtimedwait __P((const sigset_t * __restrict,
siginfo_t * __restrict, struct timespec * __restrict));
#endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */

@ -1,4 +1,4 @@
# $NetBSD: shlib_version,v 1.127 2003/01/20 20:10:34 christos Exp $
# $NetBSD: shlib_version,v 1.128 2003/02/15 21:11:48 jdolecek Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@ -11,4 +11,4 @@
# - libc/net/getaddrinfo.c, netdb.h: remove __ai_pad0
#
major=12
minor=94
minor=95

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.136 2003/02/13 14:29:04 jdolecek Exp $
# $NetBSD: Makefile.inc,v 1.137 2003/02/15 21:11:49 jdolecek Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@ -22,6 +22,9 @@ LSRCS+= ${_LSRC}
DPSRCS+=${_LSRC:MLintSys*.c}
.endif
# glue to offer userland wrappers for some syscalls
SRCS+= sigtimedwait.c sigwait.c sigwaitinfo.c
# glue to provide compatibility between GCC 1.X and 2.X and for compat
# with old syscall interfaces.
SRCS+= adjtime.c clock_settime.c ftruncate.c getdirentries.c lseek.c mmap.c \
@ -65,7 +68,8 @@ ASM= access.S acct.S bind.S chdir.S chflags.S \
setsid.S setsockopt.S setuid.S \
__shmctl13.S shmdt.S shmget.S shutdown.S \
__sigaltstack14.S __sigpending14.S __sigprocmask14.S \
__sigaction_sigtramp.S socket.S socketpair.S __stat13.S statfs.S \
__sigaction_sigtramp.S __sigtimedwait.S \
socket.S socketpair.S __stat13.S statfs.S \
swapctl.S symlink.S umask.S undelete.S unlink.S \
unmount.S utimes.S utrace.S vadvise.S \
__sysctl.S \
@ -143,7 +147,8 @@ MAN+= accept.2 access.2 acct.2 adjtime.2 bind.2 brk.2 chdir.2 \
semget.2 semop.2 send.2 setgroups.2 setpgid.2 setregid.2 \
setreuid.2 setsid.2 setuid.2 shmat.2 shmctl.2 shmget.2 \
shutdown.2 sigaction.2 sigaltstack.2 sigpending.2 \
sigprocmask.2 sigreturn.2 sigstack.2 sigsuspend.2 socket.2 \
sigprocmask.2 sigreturn.2 sigstack.2 sigsuspend.2 sigtimedwait.2 \
socket.2 \
socketpair.2 stat.2 statfs.2 swapctl.2 swapon.3 symlink.2 \
sync.2 sysarch.2 syscall.2 truncate.2 umask.2 undelete.2 \
unlink.2 utimes.2 utrace.2 vfork.2 wait.2 write.2
@ -188,6 +193,8 @@ MLINKS+=send.2 sendmsg.2 send.2 sendto.2
MLINKS+=setpgid.2 setpgrp.2
MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
MLINKS+=shmat.2 shmdt.2
MLINKS+=sigtimedwait.2 sigwaitinfo.2
MLINKS+=sigtimedwait.2 sigwait.2
MLINKS+=stat.2 fstat.2 stat.2 lstat.2
MLINKS+=statfs.2 fstatfs.2
MLINKS+=syscall.2 __syscall.2

157
lib/libc/sys/sigtimedwait.2 Normal file

@ -0,0 +1,157 @@
.\" $NetBSD: sigtimedwait.2,v 1.1 2003/02/15 21:11:49 jdolecek Exp $
.\"
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jaromir Dolecek.
.\"
.\" 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.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" 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.
.\"
.Dd February 10, 2003
.Dt SIGTIMEDWAIT 2
.Os
.Sh NAME
.Nm sigtimedwait ,
.Nm sigwaitinfo ,
.Nm sigwait
.Nd wait for queued signals
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.Fd #include \*[Lt]signal.h\*[Gt]
.Ft int
.Fn sigtimedwait "const sigset_t * restrict set" "siginfo_t * restrict info" "const struct timespec * restrict timeout"
.Ft int
.Fn sigwaitinfo "const sigset_t * restrict set" "siginfo_t * restrict info"
.Ft int
.Fn sigwait "const sigset_t * restrict set" "int * restrict sig"
.Sh DESCRIPTION
.Fn sigwaitinfo
and
.Fn sigwait
return first pending signal from the set specified by
.Fa set .
Should multiple signals from
.Fa set
be pending, the lowest numbered one is returned. The selection
order between realtime and non-realtime signals is unspecified.
If there is no signal from
.Ar set
pending at the time of the call, calling thread
is suspended until the signal would be generated.
.Pp
.Fn sigtimedwait
is exactly equal to
.Fn sigwaitinfo ,
except
.Fa timeout
specifies the maximum time interval it would suspend for.
If
.Fa timeout
is zero (tv_sec == tv_nsec == 0),
.Fn sigtimedwait
only checks current pending signals and returns immediatelly.
If
.Va NULL
is used for
.Fa timeout ,
.Fn sigtimedwait
is exactly equal to
.Fn sigwaitinfo
in all regards.
.Pp
If there are several threads waiting for given signal, exactly one of them
returns from the signal wait when the signal would be generated.
.Pp
Behaviour of these functions is unspecified if any of the signals
in
.Fa set
are unblocked at the time these functions are called.
.Sh RETURN VALUES
Upon successful completion
.Fa info
is updated with signal information, and function returns 0.
Otherwise, a \-1 is returned and the global variable
.Va errno
indicates the error.
.Sh ERRORS
.Fn sigwaitinfo
and
.Fn sigwait
always succeed.
.Pp
.Fn sigtimedwait
will fail and the
.Fa info
pointer will remain unchanged if:
.Bl -tag -width Er
.It Bq Er EAGAIN
No signal specified in
.Fa set
was generated in in specified
.Fa timeout .
.El
.Pp
.Fn sigtimedwait
may also fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The specified
.Fa timeout
was invalid.
.El
.Pp
This error is only checked if no signal from
.Fa set
is pending and it would be necessary to wait.
.Sh SEE ALSO
.Xr sigaction 2 ,
.Xr sigprocmask 2 ,
.Xr signal 7
.Sh STANDARDS
The functions
.Fn sigtimedwait ,
.Fn sigwaitinfo
and
.Fn sigwait
conform to
.St -p1003.1-2001 .
.Sh HISTORY
.Fn sigtimedwait ,
.Fn sigwaitinfo
and
.Fn sigwait
functions appeared in
.Nx 2.0 .
.Sh AUTHORS
The initial
.Nx
implementation of signal wait functions was written by
.An Jaromir Dolecek Aq jdolecek@NetBSD.org .

@ -0,0 +1,72 @@
/* $NetBSD: sigtimedwait.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: sigtimedwait.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#ifdef __weak_alias
__weak_alias(sigtimedwait,_sigtimedwait)
#endif
int _sigtimedwait __P((const sigset_t * __restrict,
siginfo_t * __restrict, const struct timespec * __restrict));
/*
* Copy timeout to local variable and call the syscall.
*/
int
_sigtimedwait(const sigset_t * __restrict set, siginfo_t * __restrict info,
const struct timespec * __restrict timeout)
{
struct timespec ts;
if (timeout) {
ts = *timeout;
return (__sigtimedwait(set, info, &ts));
} else
return (__sigtimedwait(set, info, NULL));
}

71
lib/libc/sys/sigwait.c Normal file

@ -0,0 +1,71 @@
/* $NetBSD: sigwait.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: sigwait.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <signal.h>
#ifdef __weak_alias
__weak_alias(sigwait,_sigwait)
#endif
int _sigwait __P((const sigset_t * __restrict, int * __restrict));
/*
* This is wrapper around sigtimedwait(2), providing sigwait()
* implementation for userland.
*/
int
_sigwait(const sigset_t * __restrict set, int * __restrict signum)
{
siginfo_t si;
int error;
error = sigtimedwait(set, &si, NULL);
if (!error)
*signum = si.si_signo;
return (error);
}

@ -0,0 +1,65 @@
/* $NetBSD: sigwaitinfo.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: sigwaitinfo.c,v 1.1 2003/02/15 21:11:49 jdolecek Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <signal.h>
#ifdef __weak_alias
__weak_alias(sigwaitinfo,_sigwaitinfo)
#endif
int _sigwaitinfo __P((const sigset_t * __restrict,
siginfo_t * __restrict info));
/*
* This is wrapper around sigtimedwait(2), providing sigwaitinfo()
* implementation for userland.
*/
int
_sigwaitinfo(const sigset_t * __restrict set, siginfo_t * __restrict info)
{
return (sigtimedwait(set, info, NULL));
}