home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / signals.c < prev    next >
C/C++ Source or Header  |  1990-04-28  |  3KB  |  156 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    BSD
  98.     if (InGetPrompt)
  99.         longjmp(GetPromptBuf, 1);
  100. #else
  101.     signal(SIGALRM, alarm_signal);
  102. #endif
  103. }
  104.  
  105. sighan_type
  106. pipe_signal()
  107. {
  108.     /** silently process pipe signal... **/
  109.     dprint(2, (debugfile, "*** received SIGPIPE ***\n\n"));
  110.     
  111.     pipe_abort = TRUE;    /* internal signal ... wheeee!  */
  112.  
  113.     signal(SIGPIPE, pipe_signal);
  114. }
  115.  
  116. #ifdef SIGTSTP
  117. int was_in_raw_state;
  118.  
  119. sighan_type
  120. sig_user_stop()
  121. {
  122.     /* This is called when the user presses a ^Z to stop the
  123.        process within BSD 
  124.     */
  125.     if (signal(SIGTSTP, SIG_DFL) != SIG_DFL)
  126.       signal(SIGTSTP, SIG_DFL);
  127.  
  128.     was_in_raw_state = RawState();
  129.     Raw(OFF);    /* turn it off regardless */
  130.  
  131.     printf("\n\nStopped.  Use \"fg\" to return to ELM\n\n");
  132.  
  133.     kill(0, SIGSTOP);
  134. }
  135.  
  136. sighan_type
  137. sig_return_from_user_stop()
  138. {
  139.     /** this is called when returning from a ^Z stop **/
  140.  
  141.     if (signal(SIGTSTP, sig_user_stop) == SIG_DFL)
  142.       signal(SIGTSTP, sig_user_stop);
  143.  
  144.     printf(
  145.      "\nBack in ELM. (You might need to explicitly request a redraw.)\n\n");
  146.  
  147.     if (was_in_raw_state)
  148.       Raw(ON);
  149.  
  150. #ifdef    BSD
  151.     if (InGetPrompt)
  152.         longjmp(GetPromptBuf, 1);
  153. #endif
  154. }
  155. #endif
  156.