home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / signals.c < prev    next >
C/C++ Source or Header  |  1993-09-17  |  4KB  |  162 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: signals.c,v 4.1 90/04/28 22:44:10 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    signals.c,v $
  17.  * Revision 4.1  90/04/28  22:44:10  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This set of routines traps various signals and informs the
  24.     user of the error, leaving the program in a nice, graceful
  25.     manner.
  26.  
  27. **/
  28.  
  29. #include "headers.h"
  30. #include <signal.h>
  31.  
  32. #ifdef    VOIDSIG
  33. typedef    void    sighan_type;
  34. #else
  35. typedef    int    sighan_type;
  36. #endif
  37.  
  38. extern int pipe_abort;        /* set to TRUE if receive SIGPIPE */
  39.  
  40. sighan_type
  41. quit_signal()
  42. {
  43.     dprint(1, (debugfile, "\n\n** Received SIGQUIT **\n\n\n\n"));
  44.     leave();
  45. }
  46.  
  47. sighan_type
  48. hup_signal()
  49. {
  50.     dprint(1, (debugfile, "\n\n** Received SIGHUP **\n\n\n\n"));
  51.     leave();
  52. }
  53.  
  54. sighan_type
  55. term_signal()
  56. {
  57.     dprint(1, (debugfile, "\n\n** Received SIGTERM **\n\n\n\n"));
  58.     leave();
  59. }
  60.  
  61. sighan_type
  62. ill_signal()
  63. {
  64.     dprint(1, (debugfile, "\n\n** Received SIGILL **\n\n\n\n"));
  65.     PutLine0(LINES, 0, "\n\nIllegal Instruction signal!\n\n");
  66.     emergency_exit();
  67. }
  68.  
  69. sighan_type
  70. fpe_signal()
  71. {
  72.     dprint(1, (debugfile, "\n\n** Received SIGFPE **\n\n\n\n"));
  73.     PutLine0(LINES, 0,"\n\nFloating Point Exception signal!\n\n");
  74.     emergency_exit();
  75. }
  76.  
  77. sighan_type
  78. bus_signal()
  79. {
  80.     dprint(1, (debugfile, "\n\n** Received SIGBUS **\n\n\n\n"));
  81.     PutLine0(LINES, 0,"\n\nBus Error signal!\n\n");
  82.     emergency_exit();
  83. }
  84.  
  85. sighan_type
  86. segv_signal()
  87. {
  88.     dprint(1, (debugfile,"\n\n** Received SIGSEGV **\n\n\n\n"));
  89.     PutLine0(LINES, 0,"\n\nSegment Violation signal!\n\n");
  90.     emergency_exit();
  91. }
  92.  
  93. sighan_type
  94. alarm_signal()
  95. {
  96.     /** silently process alarm signal for timeouts... **/
  97. #ifdef OS2
  98.     signal(SIGALRM, SIG_ACK);
  99.     signal(SIGALRM, alarm_signal);
  100. #endif
  101. #if defined(BSD) || defined(OS2)
  102.     if (InGetPrompt)
  103.         longjmp(GetPromptBuf, 1);
  104. #else
  105.     signal(SIGALRM, alarm_signal);
  106. #endif
  107. }
  108.  
  109. sighan_type
  110. pipe_signal()
  111. {
  112.     /** silently process pipe signal... **/
  113.     dprint(2, (debugfile, "*** received SIGPIPE ***\n\n"));
  114.  
  115.     pipe_abort = TRUE;    /* internal signal ... wheeee!  */
  116. #ifndef OS2
  117.     signal(SIGPIPE, SIG_ACK);
  118.     signal(SIGPIPE, pipe_signal);
  119. #endif
  120. }
  121.  
  122. #ifdef SIGTSTP
  123. int was_in_raw_state;
  124.  
  125. sighan_type
  126. sig_user_stop()
  127. {
  128.     /* This is called when the user presses a ^Z to stop the
  129.        process within BSD
  130.     */
  131.     if (signal(SIGTSTP, SIG_DFL) != SIG_DFL)
  132.       signal(SIGTSTP, SIG_DFL);
  133.  
  134.     was_in_raw_state = RawState();
  135.     Raw(OFF);    /* turn it off regardless */
  136.  
  137.     printf("\n\nStopped.  Use \"fg\" to return to ELM\n\n");
  138.  
  139.     kill(0, SIGSTOP);
  140. }
  141.  
  142. sighan_type
  143. sig_return_from_user_stop()
  144. {
  145.     /** this is called when returning from a ^Z stop **/
  146.  
  147.     if (signal(SIGTSTP, sig_user_stop) == SIG_DFL)
  148.       signal(SIGTSTP, sig_user_stop);
  149.  
  150.     printf(
  151.      "\nBack in ELM. (You might need to explicitly request a redraw.)\n\n");
  152.  
  153.     if (was_in_raw_state)
  154.       Raw(ON);
  155.  
  156. #ifdef    BSD
  157.     if (InGetPrompt)
  158.         longjmp(GetPromptBuf, 1);
  159. #endif
  160. }
  161. #endif
  162.