Back to index

glibc  2.9
sigpause.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,92,94-98,2000,2002,2003,2004
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 #define sigpause __rename_sigpause
00021 #include <errno.h>
00022 #include <signal.h>
00023 #include <stddef.h>         /* For NULL.  */
00024 #include <sysdep-cancel.h>
00025 #undef sigpause
00026 
00027 #include <sigset-cvt-mask.h>
00028 
00029 /* Set the mask of blocked signals to MASK,
00030    wait for a signal to arrive, and then restore the mask.  */
00031 static int
00032 do_sigpause (int sig_or_mask, int is_sig)
00033 {
00034   sigset_t set;
00035 
00036   if (is_sig != 0)
00037     {
00038       /* The modern X/Open implementation is requested.  */
00039       if (__sigprocmask (0, NULL, &set) < 0
00040          || sigdelset (&set, sig_or_mask) < 0)
00041        return -1;
00042     }
00043   else if (sigset_set_old_mask (&set, sig_or_mask) < 0)
00044     return -1;
00045 
00046   /* Note the sigpause() is a cancellation point.  But since we call
00047      sigsuspend() which itself is a cancellation point we do not have
00048      to do anything here.  */
00049   return __sigsuspend (&set);
00050 }
00051 
00052 int
00053 __sigpause (int sig_or_mask, int is_sig)
00054 {
00055   if (SINGLE_THREAD_P)
00056     return do_sigpause (sig_or_mask, is_sig);
00057 
00058   int oldtype = LIBC_CANCEL_ASYNC ();
00059 
00060   int result = do_sigpause (sig_or_mask, is_sig);
00061 
00062   LIBC_CANCEL_RESET (oldtype);
00063 
00064   return result;
00065 }
00066 libc_hidden_def (__sigpause)
00067 
00068 /* We have to provide a default version of this function since the
00069    standards demand it.  The version which is a bit more reasonable is
00070    the BSD version.  So make this the default.  */
00071 int
00072 __attribute__ ((weak))
00073 __default_sigpause (int mask)
00074 {
00075   return __sigpause (mask, 0);
00076 }
00077 #undef sigpause
00078 weak_alias (__default_sigpause, sigpause)
00079 strong_alias (__default_sigpause, __libc_sigpause)
00080 
00081 
00082 /* We have to provide a default version of this function since the
00083    standards demand it.  The version which is a bit more reasonable is
00084    the BSD version.  So make this the default.  */
00085 int
00086 __attribute__ ((weak))
00087 __xpg_sigpause (int sig)
00088 {
00089   return __sigpause (sig, 1);
00090 }
00091 strong_alias (__xpg_sigpause, __libc___xpg_sigpause)