Back to index

glibc  2.9
sigwait.c
Go to the documentation of this file.
00001 /* Copyright (C) 1997, 1998, 2000, 2002, 2003 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 #define __need_NULL
00022 #include <stddef.h>
00023 
00024 #include <sysdep-cancel.h>
00025 #include <sys/syscall.h>
00026 #include <bp-checks.h>
00027 #include <bits/libc-lock.h>
00028 
00029 extern int __syscall_rt_sigtimedwait (const sigset_t *__unbounded, siginfo_t *__unbounded,
00030                                   const struct timespec *__unbounded, size_t);
00031 
00032 
00033 /* Return any pending signal or wait for one for the given time.  */
00034 static inline int
00035 do_sigwait (const sigset_t *set, int *sig)
00036 {
00037   int ret;
00038 
00039   /* XXX The size argument hopefully will have to be changed to the
00040      real size of the user-level sigset_t.  */
00041 #ifdef INTERNAL_SYSCALL
00042   INTERNAL_SYSCALL_DECL (err);
00043   ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, CHECK_SIGSET (set),
00044                        NULL, NULL, _NSIG / 8);
00045   if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
00046     {
00047       *sig = ret;
00048       ret = 0;
00049     }
00050   else
00051     ret = INTERNAL_SYSCALL_ERRNO (ret, err);
00052 #else
00053   ret = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
00054                      NULL, NULL, _NSIG / 8);
00055   if (ret != -1)
00056     {
00057       *sig = ret;
00058       ret = 0;
00059     }
00060   else
00061     ret = errno;
00062 #endif
00063 
00064   return ret;
00065 }
00066 
00067 #ifndef SHARED
00068 weak_extern (__pthread_sigwait)
00069 #endif
00070 
00071 int
00072 __sigwait (set, sig)
00073      const sigset_t *set;
00074      int *sig;
00075 {
00076 #ifndef NOT_IN_libc
00077   return __libc_maybe_call2 (pthread_sigwait, (set, sig),
00078                           do_sigwait (set, sig));
00079 #else
00080   return do_sigwait (set, sig);
00081 #endif
00082 }
00083 libc_hidden_def (__sigwait)
00084 weak_alias (__sigwait, sigwait)
00085 strong_alias (__sigwait, __libc_sigwait)
00086 
00087 /* Cancellation is handled in __pthread_sigwait.  */
00088 LIBC_CANCEL_HANDLED ();