Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/sys add sigqueue



details:   https://anonhg.NetBSD.org/src/rev/0b9e9cf69e1e
branches:  trunk
changeset: 760642:0b9e9cf69e1e
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jan 10 04:41:27 2011 +0000

description:
add sigqueue

diffstat:

 lib/libc/sys/Makefile.inc |   10 +-
 lib/libc/sys/sigqueue.2   |  159 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/libc/sys/sigqueue.c   |   68 +++++++++++++++++++
 3 files changed, 233 insertions(+), 4 deletions(-)

diffs (280 lines):

diff -r 263f634319cb -r 0b9e9cf69e1e lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Mon Jan 10 04:41:00 2011 +0000
+++ b/lib/libc/sys/Makefile.inc Mon Jan 10 04:41:27 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.203 2010/08/06 05:26:35 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.204 2011/01/10 04:41:27 christos Exp $
 #      @(#)Makefile.inc        8.3 (Berkeley) 10/24/94
 
 # sys sources
@@ -25,8 +25,8 @@
 .endif
 
 # glue to offer userland wrappers for some syscalls
-SRCS+= posix_fadvise.c posix_madvise.c sched.c sigtimedwait.c sigwait.c \
-       sigwaitinfo.c statvfs.c swapon.c semctl.c
+SRCS+= posix_fadvise.c posix_madvise.c sched.c sigqueue.c sigtimedwait.c \
+       sigwait.c sigwaitinfo.c statvfs.c swapon.c semctl.c 
 
 # glue to provide compatibility between GCC 1.X and 2.X and for compat
 # with old syscall interfaces.
@@ -119,6 +119,7 @@
                setpriority.S \
                setregid.S setreuid.S setrlimit.S setsid.S setsockopt.S \
                setuid.S __shmctl50.S shmdt.S shmget.S shutdown.S \
+               sigqueueinfo.S \
                __sigaltstack14.S __sigpending14.S __sigaction_sigtramp.S \
                ____sigtimedwait50.S __socket30.S socketpair.S __stat50.S \
                statvfs1.S swapctl.S symlink.S __sysctl.S \
@@ -230,7 +231,7 @@
        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 sigstack.2 sigsuspend.2 sigtimedwait.2 \
+       sigprocmask.2 sigqueue.2 sigstack.2 sigsuspend.2 sigtimedwait.2 \
        socket.2 \
        socketpair.2 stat.2 statvfs.2 swapctl.2 swapon.3 symlink.2 \
        sync.2 sysarch.2 syscall.2 timer_create.2 timer_delete.2 \
@@ -295,6 +296,7 @@
 MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
 MLINKS+=shmat.2 shmdt.2
 MLINKS+=timer_settime.2 timer_gettime.2 timer_settime.2 timer_getoverrun.2
+MLINKS+=sigqueue.2 sigqueueinfo.2
 MLINKS+=sigtimedwait.2 sigwaitinfo.2
 MLINKS+=sigtimedwait.2 sigwait.2
 MLINKS+=stat.2 fstat.2 stat.2 lstat.2
diff -r 263f634319cb -r 0b9e9cf69e1e lib/libc/sys/sigqueue.2
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/sigqueue.2   Mon Jan 10 04:41:27 2011 +0000
@@ -0,0 +1,159 @@
+.\" $NetBSD: sigqueue.2,v 1.1 2011/01/10 04:41:27 christos Exp $
+.\" Copyright (c) 2005 David Xu <davidxu%FreeBSD.org@localhost>
+.\" All rights reserved.
+.\"
+.\" 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(s), this list of conditions and the following disclaimer as
+.\"    the first lines of this file unmodified other than the possible
+.\"    addition of one or more copyright notices.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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.
+.\"
+.\" $FreeBSD: src/lib/libc/sys/sigqueue.2,v 1.8 2006/09/17 21:27:34 ru Exp $
+.\"
+.Dd January 9, 2011
+.Dt SIGQUEUE 2
+.Os
+.Sh NAME
+.Nm sigqueue
+.Nd "queue a signal to a process (REALTIME)"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In signal.h
+.Ft int
+.Fn sigqueue "pid_t pid" "int signo" "const union sigval value"
+.Ft int
+.Fn sigqueueinfo "pid_t pid" "const siginfo_t *info"
+.Sh DESCRIPTION
+The
+.Fn sigqueue
+system call causes the signal specified by
+.Fa signo
+to be sent with the value specified by
+.Fa value
+to the process specified by
+.Fa pid .
+If
+.Fa signo
+is zero (the null signal), error checking is performed but
+no signal is actually sent.
+The null signal can be used to check the
+validity of PID.
+.Pp
+The conditions required for a process to have permission to queue a
+signal to another process are the same as for the
+.Xr kill 2
+system call.
+The
+.Fn sigqueue
+system call queues a signal to a single process specified by the
+.Fa pid
+argument.
+.Pp
+The
+.Fn sigqueue
+system call is implemented using
+.Fn sigqueueinfo
+and passing the appropriate information in the
+.Fa info
+argument.
+.Pp
+The
+.Fn sigqueue
+system call returns immediately.
+If the resources were
+available to queue the signal, the signal will be queued and sent to
+the receiving process.
+.Pp
+If the value of
+.Fa pid
+causes
+.Fa signo
+to be generated for the sending process, and if
+.Fa signo
+is not blocked for the calling thread and if no other thread has
+.Fa signo
+unblocked or is waiting in a
+.Fn sigwait
+system call for
+.Fa signo ,
+either
+.Fa signo
+or at least the pending, unblocked signal will be delivered to the
+calling thread before
+.Fn sigqueue
+returns.
+Should any multiple pending signals in the range
+.Dv SIGRTMIN
+to
+.Dv SIGRTMAX
+be selected for delivery, it is the lowest numbered
+one.
+The selection order between realtime and non-realtime signals, or
+between multiple pending non-realtime signals, is unspecified.
+.Sh RETURN VALUES
+.Rv -std
+.Sh ERRORS
+The
+.Fn sigqueue
+system call
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EAGAIN
+No resources are available to queue the signal.
+The process has already
+queued
+.Brq Dv SIGQUEUE_MAX
+signals that are still pending at the receiver(s),
+or a system-wide resource limit has been exceeded.
+.It Bq Er EINVAL
+The value of the
+.Fa signo
+argument is an invalid or unsupported signal number.
+.It Bq Er EEPERM
+The process does not have the appropriate privilege to send the signal
+to the receiving process.
+.It Bq Er ESRCH
+The process
+.Fa pid
+does not exist.
+.El
+.Sh SEE ALSO
+.Xr sigaction 2 ,
+.Xr sigpending 2 ,
+.Xr sigqueue 2 ,
+.Xr sigsuspend 2 ,
+.Xr sigtimedwait 2 ,
+.Xr sigwait 2 ,
+.Xr sigwaitinfo 2 ,
+.Xr pause 3 ,
+.Xr pthread_sigmask 3 ,
+.Xr siginfo 3
+.Sh STANDARDS
+The
+.Fn sigqueue
+system call conforms to
+.St -p1003.1-2004
+.Sh HISTORY
+Support for
+.Tn POSIX
+realtime signal queue first appeared in
+.Nx 6.0 .
diff -r 263f634319cb -r 0b9e9cf69e1e lib/libc/sys/sigqueue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/sigqueue.c   Mon Jan 10 04:41:27 2011 +0000
@@ -0,0 +1,68 @@
+/* $NetBSD: sigqueue.c,v 1.1 2011/01/10 04:41:27 christos Exp $ */
+
+/*-
+ * Copyright (c) 2011 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.
+ * 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: sigqueue.c,v 1.1 2011/01/10 04:41:27 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+
+/*
+ * This is wrapper around sigqueueinfo(2), providing a sigqueue()
+ * implementation for userland.
+ */
+int
+sigqueue(pid_t pid, int signo, const union sigval value)
+{
+       siginfo_t info;
+
+       (void)memset(&info, 0, sizeof(info));
+
+       info.si_signo = signo;
+       info.si_code = SI_QUEUE;
+       info.si_pid = getpid();
+       info.si_uid = geteuid();
+       info.si_value = value;
+
+       return sigqueueinfo(pid, &info);
+}



Home | Main Index | Thread Index | Old Index