Back to index

glibc  2.9
sigsuspend.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996,1997,1998,1999,2000,2002,2003,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <signal.h>
00022 #include <unistd.h>
00023 
00024 #include <sysdep-cancel.h>
00025 #include <sys/syscall.h>
00026 #include <bp-checks.h>
00027 
00028 #include <kernel-features.h>
00029 
00030 
00031 #if !__ASSUME_REALTIME_SIGNALS
00032 /* The variable is shared between all wrappers around signal handling
00033    functions which have RT equivalents.  The definition is in sigaction.c.  */
00034 extern int __libc_missing_rt_sigs;
00035 
00036 
00037 static int
00038 do_sigsuspend (const sigset_t *set)
00039 {
00040 # ifdef __NR_rt_sigsuspend
00041   /* First try the RT signals.  */
00042   if (!__libc_missing_rt_sigs)
00043     {
00044       /* XXX The size argument hopefully will have to be changed to the
00045         real size of the user-level sigset_t.  */
00046       int saved_errno = errno;
00047       int result = INLINE_SYSCALL (rt_sigsuspend, 2,
00048                                CHECK_SIGSET (set), _NSIG / 8);
00049       if (result >= 0 || errno != ENOSYS)
00050        return result;
00051 
00052       __set_errno (saved_errno);
00053       __libc_missing_rt_sigs = 1;
00054     }
00055 # endif
00056 
00057   return INLINE_SYSCALL (sigsuspend, 3, 0, 0, set->__val[0]);
00058 }
00059 #else
00060 static inline int __attribute__ ((always_inline))
00061 do_sigsuspend (const sigset_t *set)
00062 {
00063   return INLINE_SYSCALL (rt_sigsuspend, 2, CHECK_SIGSET (set), _NSIG / 8);
00064 }
00065 #endif
00066 
00067 /* Change the set of blocked signals to SET,
00068    wait until a signal arrives, and restore the set of blocked signals.  */
00069 int
00070 __sigsuspend (set)
00071      const sigset_t *set;
00072 {
00073   if (SINGLE_THREAD_P)
00074     return do_sigsuspend (set);
00075 
00076   int oldtype = LIBC_CANCEL_ASYNC ();
00077 
00078   int result = do_sigsuspend (set);
00079 
00080   LIBC_CANCEL_RESET (oldtype);
00081 
00082   return result;
00083 }
00084 libc_hidden_def (__sigsuspend)
00085 weak_alias (__sigsuspend, sigsuspend)
00086 strong_alias (__sigsuspend, __libc_sigsuspend)
00087 
00088 #ifndef NO_CANCELLATION
00089 int
00090 __sigsuspend_nocancel (set)
00091      const sigset_t *set;
00092 {
00093   return do_sigsuspend (set);
00094 }
00095 #endif