Back to index

glibc  2.9
sigprocmask.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,92,93,94,95,96,97,2002 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 <hurd.h>
00022 #include <hurd/signal.h>
00023 #include <hurd/msg.h>
00024 
00025 /* If SET is not NULL, modify the current set of blocked signals
00026    according to HOW, which may be SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
00027    If OSET is not NULL, store the old set of blocked signals in *OSET.  */
00028 int
00029 __sigprocmask (how, set, oset)
00030      int how;
00031      const sigset_t *set;
00032      sigset_t *oset;
00033 {
00034   struct hurd_sigstate *ss;
00035   sigset_t old, new;
00036   sigset_t pending;
00037 
00038   if (set != NULL)
00039     new = *set;
00040 
00041   ss = _hurd_self_sigstate ();
00042 
00043   __spin_lock (&ss->lock);
00044 
00045   old = ss->blocked;
00046 
00047   if (set != NULL)
00048     {
00049       switch (how)
00050        {
00051        case SIG_BLOCK:
00052          __sigorset (&ss->blocked, &ss->blocked, &new);
00053          break;
00054 
00055        case SIG_UNBLOCK:
00056          ss->blocked &= ~new;
00057          break;
00058 
00059        case SIG_SETMASK:
00060          ss->blocked = new;
00061          break;
00062 
00063        default:
00064          __spin_unlock (&ss->lock);
00065          errno = EINVAL;
00066          return -1;
00067        }
00068 
00069       ss->blocked &= ~_SIG_CANT_MASK;
00070     }
00071 
00072   pending = ss->pending & ~ss->blocked;
00073 
00074   __spin_unlock (&ss->lock);
00075 
00076   if (oset != NULL)
00077     *oset = old;
00078 
00079   if (pending)
00080     /* Send a message to the signal thread so it
00081        will wake up and check for pending signals.  */
00082     __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
00083 
00084   return 0;
00085 }
00086 
00087 weak_alias (__sigprocmask, sigprocmask)