# 2.11BSD#431 - /usr/src/games/warp/sig.c

##### Functions

    cont_catcher      X
    finalize          X
    mytstp            X
    sig_catcher       X
    sig_init          X
    stop_catcher      X

       1: /* $Header: /usr/src/games/warp/RCS/sig.c,v 1.1 87/07/03 01:47:11 games Exp $ */
       2:
       3: /* $Log:	sig.c,v $
       4:  * Revision 7.0.1.2   99/10/24
       5:  * Update to sigprocmask.
       6:  *
       7:  * Revision 7.0.1.1a  87/07/03  01:47:11  games
       8:  * Changed sigsetmask to use sigmask instead of calculating it (incorrectly)
       9:  * by hand.
      10:  *
      11:  * Revision 7.0.1.1  86/12/12  17:02:44  lwall
      12:  * Baseline for net release.
      13:  *
      14:  * Revision 7.0  86/10/08  15:13:24  lwall
      15:  * Split into separate files.  Added amoebas and pirates.
      16:  *
      17:  */
      18:
      19: #include "EXTERN.h"
      20: #include "warp.h"
      21: #include "play.h"
      22: #include "score.h"
      23: #include "term.h"
      24: #include "util.h"
      25: #include "INTERN.h"
      26: #include "sig.h"
      27:
      28: void
      29: sig_init()
      30: {
      31: #ifdef lint
      32:     ;
      33: #else
      34:     sigignore(SIGINT);  /* for inquiry of existence via kill call */
      35: #ifdef SIGTTOU
      36:     sigignore(SIGTTOU);
      37: #endif
      38:
      39:     sigset(SIGHUP, sig_catcher);
      40:     if (!debugging) {
      41:     sigset(SIGQUIT, sig_catcher);
      42:     sigset(SIGILL, sig_catcher);
      43:     sigset(SIGFPE, sig_catcher);
      44:     sigset(SIGBUS, sig_catcher);
      45:     sigset(SIGSEGV, sig_catcher);
      46:     sigset(SIGSYS, sig_catcher);
      47:     sigset(SIGTERM, sig_catcher);
      48:     }
      49: #ifdef SIGXCPU
      50:     sigset(SIGXCPU, sig_catcher);
      51: #endif
      52: #ifdef SIGCONT
      53:     sigset(SIGCONT, cont_catcher);
      54: #endif
      55: #ifdef SIGTSTP
      56:     sigset(SIGTSTP, stop_catcher);
      57:     sigset(SIGSTOP, stop_catcher);
      58: #endif
      59: #endif /* lint */
      60: }
      61:
      62: #ifdef SIGTSTP
      63: void
      64: cont_catcher()
      65: {
      66: #ifndef lint
      67:     sigset(SIGCONT,cont_catcher);
      68: #endif
      69:     savetty();
      70:     crmode();
      71:     raw();
      72:     noecho();
      73:     nonl();
      74: }
      75: #endif
      76:
      77: void
      78: mytstp()
      79: {
      80:     resetty();
      81: #ifdef SIGTSTP
      82:     kill(0,SIGTSTP);
      83: #else
      84:     if (fork())
      85:     wait(0);
      86:     else {
      87:     char *shell = getenv("SHELL");
      88:
      89:     setuid(getuid());
      90:     if (!*shell)
      91:         shell = "/bin/sh";
      92:     execl(shell,shell,0);
      93:     exit(1);
      94:     }
      95: #endif
      96:     rewrite();
      97: }
      98:
      99: void                    /* very much void */
     100: finalize(status)
     101: int status;
     102: {
     103:     if (bizarre)
     104:     resetty();
     105:     if (status < 0) {
     106:     chdir("/usr/tmp");
     107:     sigset(SIGILL,SIG_DFL);
     108:     abort();
     109:     }
     110:     exit(status);
     111: }
     112:
     113: /* come here on signal other than interrupt, stop, or cont */
     114:
     115: void
     116: sig_catcher(signo)
     117: {
     118: #ifdef VERBOSE
     119:     static char *signame[] = {
     120:     "",
     121:     "HUP",
     122:     "INT",
     123:     "QUIT",
     124:     "ILL",
     125:     "TRAP",
     126:     "IOT",
     127:     "EMT",
     128:     "FPE",
     129:     "KILL",
     130:     "BUS",
     131:     "SEGV",
     132:     "SYS",
     133:     "PIPE",
     134:     "ALRM",
     135:     "TERM",
     136:     "???"
     137: #ifdef SIGTSTP
     138:     ,"STOP",
     139:     "TSTP",
     140:     "CONT",
     141:     "CHLD",
     142:     "TTIN",
     143:     "TTOU",
     144:     "TINT",
     145:     "XCPU",
     146:     "XFSZ"
     147: #ifdef SIGPROF
     148:     ,"VTALARM",
     149:     "PROF"
     150: #endif
     151: #endif
     152:     };
     153: #endif
     154:
     155: #ifdef SIGTTOU
     156: #ifndef lint
     157:     sigignore(SIGTTOU);
     158: #endif /* lint */
     159: #endif
     160: #ifdef DEBUGGING
     161:     if (debug) {
     162:     printf("\r\nSIG%s--game not saved in debug\r\n",signame[signo]);
     163:     finalize(-1);
     164:     }
     165: #endif
     166:     panic++;
     167:     if (panic >= 2) {
     168:     if (panic >= 3)
     169:         abort();
     170:     chdir(SAVEDIR);
     171:     kill(0,SIGIOT);
     172:     }
     173:     (void) sigset(SIGILL,SIG_DFL);
     174:     if (signo == SIGHUP && (timer < 10 || didkill))
     175:     signo = SIGQUIT;
     176:     if (signo == SIGQUIT) { /* can't let them bomb out without penalty */
     177:     if (smarts < 20)
     178:         smarts += 4;
     179:     else if (smarts < 35)
     180:         smarts += 2;
     181:     else
     182:         smarts++;
     183:     totalscore -= possiblescore / 2;
     184:     }
     185:     save_game();
     186:     if (signo != SIGHUP && signo != SIGQUIT)
     187: #ifdef VERBOSE
     188:     IF(verbose)
     189:         printf("\r\nCaught %s%s--%s\r\n",
     190:         signo ? "a SIG" : "an internal error", signame[signo],
     191:         experimenting ? "game saved" : "bye bye");
     192:     ELSE
     193: #endif
     194: #ifdef TERSE
     195:         printf("\r\nSignal %d--bye bye\r\n",signo);
     196: #endif
     197:     switch (signo) {
     198:     case SIGBUS:
     199:     case SIGILL:
     200:     case SIGSEGV:
     201:     finalize(-signo);
     202:     }
     203:     finalize(1);                /* and blow up */
     204: }
     205:
     206: #ifdef SIGTSTP
     207: /* come here on stop signal */
     208:
     209: void
     210: stop_catcher()
     211: {
     212:     sigset_t set;
     213:
     214:     if (!waiting) {
     215:     resetty();          /* this is the point of all this */
     216: #ifdef DEBUGGING
     217:     if (debug)
     218:         write(2,"stop_catcher\r\n",13);
     219: #endif
     220:     sigset(SIGTSTP,SIG_DFL);    /* enable stop */
     221:     sigemptyset(&set);
     222:     sigaddset(&set, SIGTSTP);
     223:     (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
     224:     kill(0,SIGTSTP);        /* and do the stop */
     225:     }
     226:     sigset(SIGTSTP,stop_catcher);   /* unenable the stop */
     227: }
     228: #endif

#### Defined functions

cont_catcher defined in line 63; used 4 times

- in line 53, 67
- in /usr/src/games/warp/sig.h line 11
- in /usr/src/games/warp/warp.c line 168

finalize defined in line 99; used 24 times

- in line 163, 201-203(2)
- in /usr/src/games/warp/score.c line 40-48(3), 94, 115-119(2), 189, 218, 227, 236, 245, 689, 706-708(2)
- in /usr/src/games/warp/sig.h line 16
- in /usr/src/games/warp/term.c line 132, 149, 412
- in /usr/src/games/warp/util.c line 63, 296
- in /usr/src/games/warp/warp.c line 333

mytstp defined in line 77; used 3 times

- in /usr/src/games/warp/sig.h line 14
- in /usr/src/games/warp/us.c line 258, 272

sig_catcher defined in line 115; used 21 times

- in line 39-50(9)
- in /usr/src/games/warp/intrp.c line 116, 216, 677
- in /usr/src/games/warp/sig.h line 9
- in /usr/src/games/warp/term.c line 621, 673, 695, 756
- in /usr/src/games/warp/util.c line 107, 254, 284
- in /usr/src/games/warp/warp.h line 269

sig_init defined in line 28; used 2 times

- in /usr/src/games/warp/sig.h line 15
- in /usr/src/games/warp/warp.c line 317

stop_catcher defined in line 209; used 5 times

- in line 56-57(2), 226
- in /usr/src/games/warp/sig.h line 12
- in /usr/src/games/warp/warp.c line 165

Last modified: 1999-10-26 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1009 |