Back to index

glibc  2.9
sigprocmask.c
Go to the documentation of this file.
00001 /* Copyright (C) 1997-2001,2003,2004,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <signal.h>
00021 #include <string.h>  /* Neede for string function builtin redirection.  */
00022 #include <unistd.h>
00023 
00024 #include <sysdep.h>
00025 #include <sys/syscall.h>
00026 #include <bp-checks.h>
00027 
00028 #include <kernel-features.h>
00029 
00030 
00031 /* The variable is shared between all wrappers around signal handling
00032    functions which have RT equivalents.  The definition is in sigaction.c.  */
00033 extern int __libc_missing_rt_sigs;
00034 
00035 
00036 /* Get and/or change the set of blocked signals.  */
00037 int
00038 __sigprocmask (how, set, oset)
00039      int how;
00040      const sigset_t *set;
00041      sigset_t *oset;
00042 {
00043 #ifdef SIGCANCEL
00044   sigset_t local_newmask;
00045 
00046   /* The only thing we have to make sure here is that SIGCANCEL and
00047      SIGSETXID are not blocked.  */
00048   if (set != NULL
00049       && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
00050 # ifdef SIGSETXID
00051          || __builtin_expect (__sigismember (set, SIGSETXID), 0)
00052 # endif
00053          ))
00054     {
00055       local_newmask = *set;
00056       __sigdelset (&local_newmask, SIGCANCEL);
00057 # ifdef SIGSETXID
00058       __sigdelset (&local_newmask, SIGSETXID);
00059 # endif
00060       set = &local_newmask;
00061     }
00062 #endif
00063 
00064 #if __ASSUME_REALTIME_SIGNALS > 0
00065   return INLINE_SYSCALL (rt_sigprocmask, 4, how, CHECK_SIGSET_NULL_OK (set),
00066                       CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
00067 #else
00068 # ifdef __NR_rt_sigprocmask
00069   /* First try the RT signals.  */
00070   if (!__libc_missing_rt_sigs)
00071     {
00072       /* XXX The size argument hopefully will have to be changed to the
00073         real size of the user-level sigset_t.  */
00074       int saved_errno = errno;
00075       int result = INLINE_SYSCALL (rt_sigprocmask, 4, how,
00076                                CHECK_SIGSET_NULL_OK (set),
00077                                CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
00078 
00079       if (result >= 0 || errno != ENOSYS)
00080        return result;
00081 
00082       __set_errno (saved_errno);
00083       __libc_missing_rt_sigs = 1;
00084     }
00085 # endif
00086 
00087   return INLINE_SYSCALL (sigprocmask, 3, how, CHECK_SIGSET_NULL_OK (set),
00088                       CHECK_SIGSET_NULL_OK (oset));
00089 #endif
00090 }
00091 weak_alias (__sigprocmask, sigprocmask)