diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-23 23:23:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-23 23:23:54 +0000 |
commit | 5606e4d6f92c10af214b54a01db79cf561067e58 (patch) | |
tree | f50c5adf765ad7492736b3fb0e9ae669573e4e5e /libc/signal | |
parent | 56c9a8402ff4c9004331efc77e5a5fe62aa65014 (diff) |
More reorg. A place for everything and everything in its place...
Diffstat (limited to 'libc/signal')
-rw-r--r-- | libc/signal/Makefile | 3 | ||||
-rw-r--r-- | libc/signal/bsd_sig.c | 34 | ||||
-rw-r--r-- | libc/signal/sigblock.c | 45 | ||||
-rw-r--r-- | libc/signal/siggtmsk.c | 39 | ||||
-rw-r--r-- | libc/signal/sigjmp.c | 35 | ||||
-rw-r--r-- | libc/signal/signal.c | 20 | ||||
-rw-r--r-- | libc/signal/sigpause.c | 37 | ||||
-rw-r--r-- | libc/signal/sigstmsk.c | 46 |
8 files changed, 258 insertions, 1 deletions
diff --git a/libc/signal/Makefile b/libc/signal/Makefile index f59f2cd27..9fb8e1d46 100644 --- a/libc/signal/Makefile +++ b/libc/signal/Makefile @@ -24,7 +24,8 @@ TOPDIR=../ include $(TOPDIR)Rules.mak LIBC=$(TOPDIR)libc.a -CSRC=raise.c +CSRC=bsd_sig.c raise.c sigblock.c siggtmsk.c sigjmp.c signal.c sigpause.c sigstmsk.c + COBJS=$(patsubst %.c,%.o, $(CSRC)) OBJS=$(COBJS) diff --git a/libc/signal/bsd_sig.c b/libc/signal/bsd_sig.c new file mode 100644 index 000000000..509de87cb --- /dev/null +++ b/libc/signal/bsd_sig.c @@ -0,0 +1,34 @@ +#define __USE_BSD_SIGNAL + +#include <signal.h> + +#undef signal + +/* The `sig' bit is set if the interrupt on it + * is enabled via siginterrupt (). */ +extern sigset_t _sigintr; + +__sighandler_t +__bsd_signal (int sig, __sighandler_t handler) +{ + int ret; + struct sigaction action, oaction; + action.sa_handler = handler; + __sigemptyset (&action.sa_mask); + if (!__sigismember (&_sigintr, sig)) { +#ifdef SA_RESTART + action.sa_flags = SA_RESTART; +#else + action.sa_flags = 0; +#endif + } + else { +#ifdef SA_INTERRUPT + action.sa_flags = SA_INTERRUPT; +#else + action.sa_flags = 0; +#endif + } + ret = __sigaction (sig, &action, &oaction); + return (ret == -1) ? SIG_ERR : oaction.sa_handler; +} diff --git a/libc/signal/sigblock.c b/libc/signal/sigblock.c new file mode 100644 index 000000000..8edfe0df2 --- /dev/null +++ b/libc/signal/sigblock.c @@ -0,0 +1,45 @@ +/* Copyright (C) 1991 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <errno.h> +#define __USE_BSD +#include <signal.h> + +/* Block signals in MASK, returning the old mask. */ +int sigblock (int mask) +{ + register int sig; + sigset_t set, oset; + + if (sigemptyset(&set) < 0) + return -1; + + for (sig = 1; sig < NSIG; ++sig) + if ((mask & sigmask(sig)) && sigaddset(&set, sig) < 0) + return -1; + + if (sigprocmask(SIG_BLOCK, &set, &oset) < 0) + return -1; + + mask = 0; + for (sig = 1; sig < NSIG; ++sig) + if (sigismember(&oset, sig)) + mask |= sigmask(sig); + + return mask; +} diff --git a/libc/signal/siggtmsk.c b/libc/signal/siggtmsk.c new file mode 100644 index 000000000..517cb49fb --- /dev/null +++ b/libc/signal/siggtmsk.c @@ -0,0 +1,39 @@ +/* Copyright (C) 1993 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <errno.h> +#define __USE_BSD +#include <signal.h> + +/* Get the mask of blocked signals. */ +int siggetmask() +{ + sigset_t oset; + register int sig; + int mask; + + if (sigprocmask(SIG_SETMASK, 0, &oset) < 0) + return -1; + + mask = 0; + for (sig = 1; sig < NSIG; ++sig) + if (sigismember(&oset, sig) == 1) + mask |= sigmask(sig); + + return mask; +} diff --git a/libc/signal/sigjmp.c b/libc/signal/sigjmp.c new file mode 100644 index 000000000..ec70e0ec9 --- /dev/null +++ b/libc/signal/sigjmp.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1992, 1994, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <stddef.h> +#include <setjmp.h> +#include <signal.h> + +/* This function is called by the `sigsetjmp' macro + before doing a `__setjmp' on ENV[0].__jmpbuf. + Always return zero. */ + +int +__sigjmp_save (sigjmp_buf env, int savemask) +{ + env[0].__mask_was_saved = (savemask && + sigprocmask (SIG_BLOCK, (sigset_t *) NULL, + &env[0].__saved_mask) == 0); + + return 0; +} diff --git a/libc/signal/signal.c b/libc/signal/signal.c new file mode 100644 index 000000000..62af55f38 --- /dev/null +++ b/libc/signal/signal.c @@ -0,0 +1,20 @@ +#include <string.h> +#include <signal.h> + +__sighandler_t +__signal (int sig, __sighandler_t handler, int flags) +{ + int ret; + struct sigaction action, oaction; + memset(&action, 0, sizeof(struct sigaction)); + action.sa_handler = handler; + action.sa_flags = flags; + ret = sigaction (sig, &action, &oaction); + return (ret == -1) ? SIG_ERR : oaction.sa_handler; +} + +__sighandler_t +signal (int sig, __sighandler_t handler) +{ + return __signal(sig, handler, (SA_ONESHOT | SA_NOMASK | SA_INTERRUPT) & ~SA_RESTART); +} diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c new file mode 100644 index 000000000..ff9809482 --- /dev/null +++ b/libc/signal/sigpause.c @@ -0,0 +1,37 @@ +/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <errno.h> +#include <signal.h> + +#undef sigpause + +/* Set the mask of blocked signals to MASK, + wait for a signal to arrive, and then restore the mask. */ +int sigpause(int mask) +{ + sigset_t set; + int sig; + + sigemptyset(&set); + for (sig = 1; sig < NSIG; ++sig) + if (mask & sigmask(sig)) + sigaddset(&set, sig); + + return sigsuspend (&set); +} diff --git a/libc/signal/sigstmsk.c b/libc/signal/sigstmsk.c new file mode 100644 index 000000000..6b1876b32 --- /dev/null +++ b/libc/signal/sigstmsk.c @@ -0,0 +1,46 @@ +/* Copyright (C) 1993 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <errno.h> +#define __USE_BSD +#include <signal.h> + +/* Set the mask of blocked signals to MASK, returning the old mask. */ +int sigsetmask (int mask) +{ + register int sig; + sigset_t set, oset; + + if (sigemptyset(&set) < 0) + return -1; + + for (sig = 1; sig < NSIG; ++sig) + if ((mask & sigmask(sig)) && + sigaddset(&set, sig) < 0) + return -1; + + if (sigprocmask(SIG_SETMASK, &set, &oset) < 0) + return -1; + + mask = 0; + for (sig = 1; sig < NSIG; ++sig) + if (sigismember(&oset, sig) == 1) + mask |= sigmask(sig); + + return mask; +} |