1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)pl_1.c	5.1 (Berkeley) 5/29/85";
   9: #endif not lint
  10: 
  11: #include "player.h"
  12: #include <sys/types.h>
  13: #include <sys/wait.h>
  14: 
  15: /*
  16:  * If we get here before a ship is chosen, then ms == 0 and
  17:  * we don't want to update the score file, or do any Write's either.
  18:  * We can assume the sync file is already created and may need
  19:  * to be removed.
  20:  * Of course, we don't do any more Sync()'s if we got here
  21:  * because of a Sync() failure.
  22:  */
  23: leave(conditions)
  24: int conditions;
  25: {
  26:     (void) signal(SIGHUP, SIG_IGN);
  27:     (void) signal(SIGINT, SIG_IGN);
  28:     (void) signal(SIGQUIT, SIG_IGN);
  29:     (void) signal(SIGALRM, SIG_IGN);
  30:     (void) signal(SIGCHLD, SIG_IGN);
  31: 
  32:     if (done_curses) {
  33:         Signal("It looks like you've had it!",
  34:             (struct ship *)0);
  35:         switch (conditions) {
  36:         case LEAVE_QUIT:
  37:             break;
  38:         case LEAVE_CAPTURED:
  39:             Signal("Your ship was captured.",
  40:                 (struct ship *)0);
  41:             break;
  42:         case LEAVE_HURRICAN:
  43:             Signal("Hurricane!  All ships destroyed.",
  44:                 (struct ship *)0);
  45:             break;
  46:         case LEAVE_DRIVER:
  47:             Signal("The driver died.", (struct ship *)0);
  48:             break;
  49:         case LEAVE_SYNC:
  50:             Signal("Synchronization error.", (struct ship *)0);
  51:             break;
  52:         default:
  53:             Signal("A funny thing happened (%d).",
  54:                 (struct ship *)0, conditions);
  55:         }
  56:     } else {
  57:         switch (conditions) {
  58:         case LEAVE_QUIT:
  59:             break;
  60:         case LEAVE_DRIVER:
  61:             printf("The driver died.\n");
  62:             break;
  63:         case LEAVE_FORK:
  64:             perror("fork");
  65:             break;
  66:         case LEAVE_SYNC:
  67:             printf("Synchronization error\n.");
  68:             break;
  69:         default:
  70:             printf("A funny thing happened (%d).\n",
  71:                 conditions);
  72:         }
  73:     }
  74: 
  75:     if (ms != 0) {
  76:         log(ms);
  77:         if (conditions != LEAVE_SYNC) {
  78:             makesignal(ms, "Captain %s relinquishing.",
  79:                 (struct ship *)0, mf->captain);
  80:             Write(W_END, ms, 0, 0, 0, 0, 0);
  81:             (void) Sync();
  82:         }
  83:     }
  84:     sync_close(!hasdriver);
  85:     cleanupscreen();
  86:     exit(0);
  87: }
  88: 
  89: choke()
  90: {
  91:     leave(LEAVE_QUIT);
  92: }
  93: 
  94: child()
  95: {
  96:     union wait status;
  97:     int pid;
  98: 
  99:     (void) signal(SIGCHLD, SIG_IGN);
 100:     do {
 101:         pid = wait3(&status, WNOHANG, (struct rusage *)0);
 102:         if (pid < 0 || pid > 0 && !WIFSTOPPED(status))
 103:             hasdriver = 0;
 104:     } while (pid > 0);
 105:     (void) signal(SIGCHLD, child);
 106: }

Defined functions

child defined in line 94; used 3 times
choke defined in line 89; used 3 times
leave defined in line 23; used 11 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-05-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3316
Valid CSS Valid XHTML 1.0 Strict