Back to index

glibc  2.9
signal.c
Go to the documentation of this file.
00001 /* BSD-like signal function.
00002    Copyright (C) 1991,1992,1996,1997,2000,2002,2005
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <errno.h>
00022 #include <signal.h>
00023 #include <string.h>  /* For the real memset prototype.  */
00024 
00025 
00026 sigset_t _sigintr attribute_hidden;              /* Set by siginterrupt.  */
00027 
00028 /* Set the handler for the signal SIG to HANDLER,
00029    returning the old handler, or SIG_ERR on error.  */
00030 __sighandler_t
00031 __bsd_signal (sig, handler)
00032      int sig;
00033      __sighandler_t handler;
00034 {
00035   struct sigaction act, oact;
00036 
00037   /* Check signal extents to protect __sigismember.  */
00038   if (handler == SIG_ERR || sig < 1 || sig >= NSIG)
00039     {
00040       __set_errno (EINVAL);
00041       return SIG_ERR;
00042     }
00043 
00044   act.sa_handler = handler;
00045   if (__sigemptyset (&act.sa_mask) < 0
00046       || __sigaddset (&act.sa_mask, sig) < 0)
00047     return SIG_ERR;
00048   act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART;
00049   if (__sigaction (sig, &act, &oact) < 0)
00050     return SIG_ERR;
00051 
00052   return oact.sa_handler;
00053 }
00054 weak_alias (__bsd_signal, bsd_signal)
00055 weak_alias (__bsd_signal, signal)
00056 weak_alias (__bsd_signal, ssignal)