home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XT.ZIP / RN / FINAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-21  |  7.3 KB  |  362 lines

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