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

Defined functions

cont_catcher defined in line 206; used 3 times
final_init defined in line 23; used 2 times
int_catcher defined in line 81; used 3 times
stop_catcher defined in line 185; used 3 times
Last modified: 1989-04-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3021
Valid CSS Valid XHTML 1.0 Strict