home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / final.c < prev    next >
Text File  |  1990-12-02  |  5KB  |  260 lines

  1. /* $Header: final.c,v 4.3.2.8 90/04/14 19:37:14 sob Exp $
  2.  *
  3.  * $Log:    final.c,v $
  4.  * Revision 4.3.2.8  90/04/14  19:37:14  sob
  5.  * Added better support for the NeXT.
  6.  * 
  7.  * Revision 4.3.2.7  90/03/17  21:33:49  sob
  8.  * cleaned up a bit
  9.  * 
  10.  * Revision 4.3.2.6  90/03/17  16:48:25  sob
  11.  * Added changes to insure that rrn cleans up its temporary files when
  12.  * exiting.
  13.  * 
  14.  * Revision 4.3.2.5  89/11/28  01:51:28  sob
  15.  * Now handles SIGWINCH correctly.
  16.  * 
  17.  * Revision 4.3.2.4  89/11/27  01:30:24  sob
  18.  * Altered NNTP code per ideas suggested by Bela Lubkin
  19.  * <filbo@gorn.santa-cruz.ca.us>
  20.  * 
  21.  * Revision 4.3.2.3  89/11/08  02:25:07  sob
  22.  * Integrated modifications from other RRN patches colleceted from USENET
  23.  * 
  24.  * Revision 4.3.2.2  89/11/07  23:26:31  sob
  25.  * Added some fixes that relate to SIGSTP
  26.  * 
  27.  * Revision 4.3.2.1  89/11/06  00:16:08  sob
  28.  * Added RRN support from NNTP 1.5
  29.  *
  30.  * Revision 4.3  85/05/01  11:38:08  lwall
  31.  * Baseline for release with 4.3bsd.
  32.  * 
  33.  */
  34.  
  35. #include "EXTERN.h"
  36. #include "common.h"
  37. #include "util.h"
  38. #include "term.h"
  39. #include "ng.h"
  40. #include "init.h"
  41. #include "bits.h"
  42. #include "last.h"
  43. #include "rcstuff.h"
  44. #include "ngdata.h"
  45. #include "artio.h"
  46. #ifdef OSK
  47. #include "backpage.h"
  48. #endif
  49. #include "INTERN.h"
  50. #include "final.h"
  51.  
  52. void
  53. final_init()
  54. {
  55. #ifdef SIGTSTP
  56.     sigset(SIGTSTP, stop_catcher);    /* job control signals */
  57.     sigset(SIGTTOU, stop_catcher);    /* job control signals */
  58.     sigset(SIGTTIN, stop_catcher);    /* job control signals */
  59. #endif
  60.  
  61.     sigset(SIGINT, int_catcher);    /* always catch interrupts */
  62.     sigset(SIGHUP, sig_catcher);    /* and hangups */
  63. #ifndef lint
  64.     sigignore(SIGEMT);
  65. #endif lint
  66.  
  67.     sigset(SIGILL, sig_catcher);
  68.     sigset(SIGTRAP, sig_catcher);
  69.     sigset(SIGFPE, sig_catcher);
  70.     sigset(SIGBUS, sig_catcher);
  71.     sigset(SIGSEGV, sig_catcher);
  72.     sigset(SIGSYS, sig_catcher);
  73.     sigset(SIGTERM, sig_catcher);
  74. #ifdef SIGXCPU
  75.     sigset(SIGXCPU, sig_catcher);
  76. #endif
  77. #ifdef SIGXFSZ
  78.     sigset(SIGXFSZ, sig_catcher);
  79. #endif
  80. #ifdef SIGWINCH
  81.     sigset(SIGWINCH, winch_catcher);
  82. #endif
  83. }
  84.  
  85. void                    /* very much void */
  86. finalize(status)
  87. int status;
  88. {
  89. #ifdef SERVER
  90.     char artname[32];
  91. #endif SERVER
  92.  
  93.     if (bizarre)
  94.     resetty();
  95. #ifdef OSK
  96.     if (lockunit >= 0) close(lockunit);
  97. #endif
  98.     if (lockname && *lockname)
  99.      UNLINK(lockname);
  100. #ifdef SERVER
  101.     if (*active_name)
  102.     UNLINK(active_name);
  103.     if (openart) {
  104.      char artname[32];
  105.      sprintf(artname, "/tmp/rrn%ld.%d", (long)openart, getpid());
  106.      UNLINK(artname);
  107.     }
  108.     close_server();
  109. #endif SERVER
  110. #ifdef OSK
  111.     if (varyfd > 0) {
  112.         close(varyfd);
  113.     UNLINK(filexp(VARYNAME));
  114.     }
  115. #endif
  116.     if (status < 0) {
  117. #ifndef OSK
  118.     chdir("/usr/tmp");
  119. #endif
  120.     sigset(SIGILL,SIG_DFL);
  121.     abort();
  122.     }
  123.     exit(status);
  124. }
  125.  
  126. /* come here on interrupt */
  127.  
  128. int
  129. int_catcher()
  130. {
  131.     sigset(SIGINT,int_catcher);
  132. #ifdef DEBUGGING
  133.     if (debug)
  134.     write(2,"int_catcher\n",12);
  135. #endif
  136.     if (!waiting) {
  137.     if (int_count) {        /* was there already an interrupt? */
  138.         write(2,"\nBye-bye.\n",10);
  139.         sig_catcher(0);        /* emulate the other signals */
  140.     }
  141.     int_count++;
  142.     }
  143. }
  144.  
  145. /* come here on signal other than interrupt, stop, or cont */
  146.  
  147. int
  148. sig_catcher(signo)
  149. {
  150. #ifdef VERBOSE
  151.     static char *signame[] = {
  152.     "",
  153.     "HUP",
  154.     "INT",
  155.     "QUIT",
  156.     "ILL",
  157.     "TRAP",
  158.     "IOT",
  159.     "EMT",
  160.     "FPE",
  161.     "KILL",
  162.     "BUS",
  163.     "SEGV",
  164.     "SYS",
  165.     "PIPE",
  166.     "ALRM",
  167.     "TERM",
  168.     "???"
  169. #ifdef SIGTSTP
  170.     ,"STOP",
  171.     "TSTP",
  172.     "CONT",
  173.     "CHLD",
  174.     "TTIN",
  175.     "TTOU",
  176.     "TINT",
  177.     "XCPU",
  178.     "XFSZ"
  179. #ifdef SIGPROF
  180.     ,"VTALARM",
  181.     "PROF"
  182. #endif
  183. #endif
  184.     };
  185. #endif
  186.  
  187. #ifdef DEBUGGING
  188.     if (debug) {
  189.     printf("\nSIG%s--.newsrc not restored in debug\n",signame[signo]);
  190.     finalize(-1);
  191.     }
  192. #endif
  193.     if (panic)
  194.     abort();
  195.     (void) sigset(SIGILL,SIG_DFL);
  196.     panic = TRUE;            /* disable terminal I/O */
  197.     if (doing_ng) {            /* need we reconstitute rc line? */
  198.     yankback();
  199.     restore_ng();            /* then do so (hope this works) */
  200.     }
  201.     doing_ng = FALSE;
  202.     if (rc_changed)            /* need we write .newsrc out? */
  203.     write_rc();            /* then do so */
  204.     rc_changed = FALSE;
  205.     if (signo != SIGHUP)
  206. #ifdef VERBOSE
  207.     IF(verbose)
  208.         printf("\nCaught %s%s--.newsrc restored\n",
  209.         signo ? "a SIG" : "an internal error", signame[signo]);
  210.     ELSE
  211. #endif
  212. #ifdef TERSE
  213.         printf("\nSignal %d--bye bye\n",signo);
  214. #endif
  215.     switch (signo) {
  216.     case SIGBUS:
  217.     case SIGILL:
  218.     case SIGSEGV:
  219.     finalize(-signo);
  220.     }
  221.     finalize(1);                /* and blow up */
  222. }
  223.  
  224. #ifdef SIGTSTP
  225. /* come here on stop signal */
  226.  
  227. int
  228. stop_catcher(signo)
  229. int signo;
  230. {
  231.     if (!waiting) {
  232.     checkpoint_rc();        /* good chance of crash while stopped */
  233.     resetty();            /* this is the point of all this */
  234. #ifdef DEBUGGING
  235.     if (debug)
  236.         write(2,"stop_catcher\n",13);
  237. #endif
  238.     sigset(signo,SIG_DFL);    /* enable stop */
  239. #ifdef SIGBLOCK
  240.     sigsetmask(sigblock(0) & ~(1 << (signo-1)));
  241. #endif
  242.     kill(0,signo);        /* and do the stop */
  243.         savetty();
  244. #ifdef MAILCALL
  245.         mailcount = 0;            /* force recheck */
  246. #endif
  247.         if (!panic) {
  248.         if (!waiting) {
  249.             noecho();            /* set no echo */
  250.             crmode();            /* set cbreak mode */
  251.             forceme("\f");        /* cause a refresh */
  252.                     /* (defined only if TIOCSTI defined) */
  253.         errno = 0;            /* needed for getcmd */
  254.         }
  255.         }
  256.     }
  257.     sigset(signo,stop_catcher);    /* unenable the stop */
  258. }
  259. #endif
  260.