home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/setup,v $
- * $Date: 1996/11/06 22:01:42 $
- * $Revision: 1.2 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: setup,v $
- * Revision 1.2 1996/11/06 22:01:42 unixlib
- * Yet more changes by NB, PB and SC.
- *
- * Revision 1.1 1996/10/30 22:04:51 unixlib
- * Initial revision
- *
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: setup,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
-
- /* signal.c.setup: Written by Nick Burrett, 1 September 1996. */
-
- #include <stdio.h>
- #include <signal.h>
- #include <unixlib/sigstate.h>
-
- /* #define DEBUG */
-
- /* This function chooses a suitable execution environment
- for the signal handler and calls the appropriate function
- to perform the job.
-
- Return 0 on sucess, 1 on fail. */
-
- int
- __unixlib_setup_sighandler (struct unixlib_sigstate *ss,
- sighandler_t handler,
- int signo, int sigcode, int flags)
- {
- int system_stack;
-
- sigcode = sigcode;
- #ifdef DEBUG
- printf ("Entered unixlib_setup_sighandler: signo = %d, handler = %x\n",
- signo, (int)handler);
- #endif
- system_stack = ((ss->signalstack.ss_flags & SA_DISABLE)
- || ss->signalstack.ss_size == 0
- || ss->signalstack.ss_sp == 0) ? 1 : 0;
-
- /* The user has requested to execute the signal on a sigstack
- but it can only be executed on the system stack. Return failure. */
- if ((flags & SA_ONSTACK) && system_stack)
- {
- #ifdef DEBUG
- printf ("unixlib_setup_sighandler: bad system stack\n");
- printf (" ss_size = %d, ss_sp = %d, ss_flags = %d\n",
- (int)ss->signalstack.ss_size,
- (int)ss->signalstack.ss_sp,
- (int)ss->signalstack.ss_flags);
- #endif
- return 1;
- }
-
- /* If the SA_DISABLE flag is set, we will not execute
- this signal on a signal stack.
-
- Look out for problems where the stack pointer is zero or the
- stack size is zero. */
- if (system_stack)
- {
- #ifdef DEBUG
- printf (" unixlib_setup_sighandler: executing off normal stack\n");
- #endif
- __unixlib_exec_sig (handler, signo);
- return 0;
- }
-
- /* Specify that the signal stack is currently in use. */
- ss->signalstack.ss_flags |= SA_ONSTACK;
-
- /* If ss_size == -1, then this sigaltstack was the result of
- a BSD sigstack conversion. Run the BSD alternative signal
- executor. */
- if (ss->signalstack.ss_size == -1)
- {
- #ifdef DEBUG
- printf (" unixlib_setup_sighandler: executing off BSD stack\n");
- #endif
- __unixlib_exec_sigstack_bsd (ss->signalstack.ss_sp, handler, signo);
- }
- else
- {
- #ifdef DEBUG
- printf (" unixlib_setup_sighandler: executing off POSIX stack\n");
- #endif
- __unixlib_exec_sigstack (ss->signalstack.ss_sp, ss->signalstack.ss_size,
- handler, signo);
- }
- /* Say that the signal stack is no longer in use. */
- ss->signalstack.ss_flags &= ~SA_ONSTACK;
-
- return 0;
- }
-