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

Defined functions

cont_catcher defined in line 196; used 3 times
final_init defined in line 22; used 2 times
int_catcher defined in line 71; used 3 times
stop_catcher defined in line 175; used 3 times
Last modified: 1986-03-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1558
Valid CSS Valid XHTML 1.0 Strict