home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / utils / elm / sources / signals.c < prev    next >
C/C++ Source or Header  |  1992-08-04  |  4KB  |  161 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. #if defined(BSD) || defined(OS2)
  98.     if (InGetPrompt)
  99.         longjmp(GetPromptBuf, 1);
  100. #ifdef OS2
  101.     signal(SIGALRM, SIG_ACK);
  102.     signal(SIGALRM, alarm_signal);
  103. #endif
  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, pipe_signal);
  118. #endif
  119. }
  120.  
  121. #ifdef SIGTSTP
  122. int was_in_raw_state;
  123.  
  124. sighan_type
  125. sig_user_stop()
  126. {
  127.     /* This is called when the user presses a ^Z to stop the
  128.        process within BSD
  129.     */
  130.     if (signal(SIGTSTP, SIG_DFL) != SIG_DFL)
  131.       signal(SIGTSTP, SIG_DFL);
  132.  
  133.     was_in_raw_state = RawState();
  134.     Raw(OFF);    /* turn it off regardless */
  135.  
  136.     printf("\n\nStopped.  Use \"fg\" to return to ELM\n\n");
  137.  
  138.     kill(0, SIGSTOP);
  139. }
  140.  
  141. sighan_type
  142. sig_return_from_user_stop()
  143. {
  144.     /** this is called when returning from a ^Z stop **/
  145.  
  146.     if (signal(SIGTSTP, sig_user_stop) == SIG_DFL)
  147.       signal(SIGTSTP, sig_user_stop);
  148.  
  149.     printf(
  150.      "\nBack in ELM. (You might need to explicitly request a redraw.)\n\n");
  151.  
  152.     if (was_in_raw_state)
  153.       Raw(ON);
  154.  
  155. #ifdef    BSD
  156.     if (InGetPrompt)
  157.         longjmp(GetPromptBuf, 1);
  158. #endif
  159. }
  160. #endif
  161.