home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Shells / zsh-3.0.5-MIHS / src / Src / signals.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-25  |  3.4 KB  |  99 lines

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