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

Defined functions

cont_catcher defined in line 192; used 3 times
final_init defined in line 21; used 2 times
int_catcher defined in line 67; used 3 times
stop_catcher defined in line 171; used 3 times
Last modified: 1985-06-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1340
Valid CSS Valid XHTML 1.0 Strict