1/*
2 * signals.h - header file for signals handling code
3 *
4 * This file is part of zsh, the Z shell.
5 *
6 * Copyright (c) 1992-1997 Paul Falstad
7 * All rights reserved.
8 *
9 * Permission is hereby granted, without written agreement and without
10 * license or royalty fees, to use, copy, modify, and distribute this
11 * software and to distribute modified versions of this software for any
12 * purpose, provided that the above copyright notice and the following
13 * two paragraphs appear in all copies of this software.
14 *
15 * In no event shall Paul Falstad or the Zsh Development Group be liable
16 * to any party for direct, indirect, special, incidental, or consequential
17 * damages arising out of the use of this software and its documentation,
18 * even if Paul Falstad and the Zsh Development Group have been advised of
19 * the possibility of such damage.
20 *
21 * Paul Falstad and the Zsh Development Group specifically disclaim any
22 * warranties, including, but not limited to, the implied warranties of
23 * merchantability and fitness for a particular purpose.  The software
24 * provided hereunder is on an "as is" basis, and Paul Falstad and the
25 * Zsh Development Group have no obligation to provide maintenance,
26 * support, updates, enhancements, or modifications.
27 *
28 */
29
30#define SIGNAL_HANDTYPE RETSIGTYPE (*)_((int))
31
32#ifndef HAVE_KILLPG
33# define killpg(pgrp,sig) kill(-(pgrp),sig)
34#endif
35
36#define SIGZERR   (SIGCOUNT+1)
37#define SIGDEBUG  (SIGCOUNT+2)
38#define VSIGCOUNT (SIGCOUNT+3)
39#define SIGEXIT    0
40
41#ifdef SV_BSDSIG
42# define SV_INTERRUPT SV_BSDSIG
43#endif
44
45/* If not a POSIX machine, then we create our *
46 * own POSIX style signal sets functions.     */
47#ifndef POSIX_SIGNALS
48# define sigemptyset(s)    (*(s) = 0)
49# if NSIG == 32
50#  define sigfillset(s)    (*(s) = ~(sigset_t)0, 0)
51# else
52#  define sigfillset(s)    (*(s) = (1 << NSIG) - 1, 0)
53# endif
54# define sigaddset(s,n)    (*(s) |=  (1 << ((n) - 1)), 0)
55# define sigdelset(s,n)    (*(s) &= ~(1 << ((n) - 1)), 0)
56# define sigismember(s,n)  ((*(s) & (1 << ((n) - 1))) != 0)
57#endif   /* ifndef POSIX_SIGNALS */
58
59#define child_block()      signal_block(sigchld_mask)
60#define child_unblock()    signal_unblock(sigchld_mask)
61
62/* ignore a signal */
63#define signal_ignore(S)   signal(S, SIG_IGN)
64
65/* return a signal to it default action */
66#define signal_default(S)  signal(S, SIG_DFL)
67
68/* Use a circular queue to save signals caught during    *
69 * critical sections of code.  You call queue_signals to *
70 * start queueing, and unqueue_signals to process the    *
71 * queue and stop queueing.  Since the kernel doesn't    *
72 * queue signals, it is probably overkill for zsh to do  *
73 * this, but it shouldn't hurt anything to do it anyway. */
74
75#define MAX_QUEUE_SIZE 128
76
77#define queue_signals()    (queueing_enabled++)
78
79#define run_queued_signals() do { \
80    while (queue_front != queue_rear) {      /* while signals in queue */ \
81	sigset_t oset; \
82	queue_front = (queue_front + 1) % MAX_QUEUE_SIZE; \
83	oset = signal_setmask(signal_mask_queue[queue_front]); \
84	zhandler(signal_queue[queue_front]);  /* handle queued signal   */ \
85	signal_setmask(oset); \
86    } \
87} while (0)
88
89#define unqueue_signals()  do { \
90    DPUTS(!queueing_enabled, "BUG: unqueue_signals called but not queueing"); \
91    if (!--queueing_enabled) run_queued_signals(); \
92} while (0)
93
94#define queue_signal_level() queueing_enabled
95
96#define dont_queue_signals() do { \
97    queueing_enabled = 0; \
98    run_queued_signals(); \
99} while (0)
100
101#define restore_queue_signals(q) (queueing_enabled = (q))
102
103#ifdef BSD_SIGNALS
104#define signal_block(S) sigblock(S)
105#else
106extern sigset_t signal_block _((sigset_t));
107#endif  /* BSD_SIGNALS   */
108
109extern sigset_t signal_unblock _((sigset_t));
110