Imported from ../bash-2.04.tar.gz.
[platform/upstream/bash.git] / sig.h
1 /* sig.h -- header file for signal handler definitions. */
2
3 /* Copyright (C) 1994 Free Software Foundation, Inc.
4
5    This file is part of GNU Bash, the Bourne Again SHell.
6
7    Bash is free software; you can redistribute it and/or modify it under
8    the terms of the GNU General Public License as published by the Free
9    Software Foundation; either version 2, or (at your option) any later
10    version.
11
12    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13    WARRANTY; without even the implied warranty of MERCHANTABILITY or
14    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15    for more details.
16
17    You should have received a copy of the GNU General Public License along
18    with Bash; see the file COPYING.  If not, write to the Free Software
19    Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
20
21 /* Make sure that this is included *after* config.h! */
22
23 #if !defined (_SIG_H_)
24 #  define _SIG_H_
25
26 #include "stdc.h"
27
28 #if !defined (SIGABRT) && defined (SIGIOT)
29 #  define SIGABRT SIGIOT
30 #endif
31
32 #define sighandler RETSIGTYPE
33 typedef RETSIGTYPE SigHandler ();
34
35 #if defined (VOID_SIGHANDLER)
36 #  define SIGRETURN(n)  return
37 #else
38 #  define SIGRETURN(n)  return(n)
39 #endif /* !VOID_SIGHANDLER */
40
41 /* Here is a definition for set_signal_handler () which simply expands to
42    a call to signal () for non-Posix systems.  The code for set_signal_handler
43    in the Posix case resides in general.c. */
44 #if !defined (HAVE_POSIX_SIGNALS)
45 #  define set_signal_handler(sig, handler) (SigHandler *)signal (sig, handler)
46 #else
47 extern SigHandler *set_signal_handler ();       /* in sig.c */
48 #endif /* _POSIX_VERSION */
49
50 /* Definitions used by the job control code. */
51 #if defined (JOB_CONTROL)
52
53 #if !defined (SIGCHLD) && defined (SIGCLD)
54 #  define SIGCHLD SIGCLD
55 #endif
56
57 #if !defined (HAVE_POSIX_SIGNALS) && !defined (sigmask)
58 #  define sigmask(x) (1 << ((x)-1))
59 #endif /* !HAVE_POSIX_SIGNALS && !sigmask */
60
61 #if !defined (HAVE_POSIX_SIGNALS)
62 #  if !defined (SIG_BLOCK)
63 #    define SIG_BLOCK 2
64 #    define SIG_SETMASK 3
65 #  endif /* SIG_BLOCK */
66
67 /* sigset_t defined in config.h */
68
69 /* Make sure there is nothing inside the signal set. */
70 #  define sigemptyset(set) (*(set) = 0)
71
72 /* Initialize the signal set to hold all signals. */
73 #  define sigfillset(set) (*set) = sigmask (NSIG) - 1
74
75 /* Add SIG to the contents of SET. */
76 #  define sigaddset(set, sig) *(set) |= sigmask (sig)
77
78 /* Delete SIG from signal set SET. */
79 #  define sigdelset(set, sig) *(set) &= ~sigmask (sig)
80
81 /* Is SIG a member of the signal set SET? */
82 #  define sigismember(set, sig) ((*(set) & sigmask (sig)) != 0)
83
84 /* Suspend the process until the reception of one of the signals
85    not present in SET. */
86 #  define sigsuspend(set) sigpause (*(set))
87 #endif /* !HAVE_POSIX_SIGNALS */
88
89 /* These definitions are used both in POSIX and non-POSIX implementations. */
90
91 #define BLOCK_SIGNAL(sig, nvar, ovar) \
92   sigemptyset (&nvar); \
93   sigaddset (&nvar, sig); \
94   sigemptyset (&ovar); \
95   sigprocmask (SIG_BLOCK, &nvar, &ovar)
96
97 #if defined (HAVE_POSIX_SIGNALS)
98 #  define BLOCK_CHILD(nvar, ovar) \
99         BLOCK_SIGNAL (SIGCHLD, nvar, ovar)
100 #  define UNBLOCK_CHILD(ovar) \
101         sigprocmask (SIG_SETMASK, &ovar, (sigset_t *) NULL)
102 #else /* !HAVE_POSIX_SIGNALS */
103 #  define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD))
104 #  define UNBLOCK_CHILD(ovar) sigsetmask (ovar)
105 #endif /* !HAVE_POSIX_SIGNALS */
106
107 #endif /* JOB_CONTROL */
108
109 /* Functions from sig.c. */
110 extern sighandler termination_unwind_protect __P((int));
111 extern sighandler sigint_sighandler __P((int));
112 extern void initialize_signals __P((void));
113 extern void reinitialize_signals __P((void));
114 extern void initialize_terminating_signals __P((void));
115 extern void reset_terminating_signals __P((void));
116 extern void throw_to_top_level __P((void));
117 extern void jump_to_top_level __P((int));
118
119 /* Functions defined in trap.c. */
120 extern SigHandler *set_sigint_handler __P((void));
121 extern SigHandler *trap_to_sighandler __P((int));
122 extern sighandler trap_handler __P((int));
123
124 #endif /* _SIG_H_ */