Commit | Line | Data |
---|---|---|
b5f0675e | 1 | /* |
1e008c14 DF |
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. | |
b5f0675e EW |
5 | */ |
6 | ||
c77f0542 | 7 | #ifndef lint |
1e008c14 DF |
8 | static char sccsid[] = "@(#)pl_1.c 5.1 (Berkeley) %G%"; |
9 | #endif not lint | |
7fc06086 | 10 | |
c77f0542 CL |
11 | #include "player.h" |
12 | #include <sys/types.h> | |
6c17b19a | 13 | #include <sys/wait.h> |
c77f0542 | 14 | |
a466c703 EW |
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. | |
6c9d2a3c EW |
20 | * Of course, we don't do any more Sync()'s if we got here |
21 | * because of a Sync() failure. | |
a466c703 | 22 | */ |
b3a57661 EW |
23 | leave(conditions) |
24 | int conditions; | |
c77f0542 | 25 | { |
b3a57661 EW |
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); | |
c77f0542 | 31 | |
a466c703 EW |
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: | |
a466c703 EW |
47 | Signal("The driver died.", (struct ship *)0); |
48 | break; | |
6c9d2a3c EW |
49 | case LEAVE_SYNC: |
50 | Signal("Synchronization error.", (struct ship *)0); | |
51 | break; | |
a466c703 EW |
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: | |
6c9d2a3c EW |
64 | perror("fork"); |
65 | break; | |
66 | case LEAVE_SYNC: | |
67 | printf("Synchronization error\n."); | |
a466c703 EW |
68 | break; |
69 | default: | |
70 | printf("A funny thing happened (%d).\n", | |
71 | conditions); | |
72 | } | |
73 | } | |
74 | ||
75 | if (ms != 0) { | |
6c9d2a3c EW |
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(); | |
7fc06086 | 82 | } |
b3a57661 | 83 | } |
a466c703 | 84 | sync_close(!hasdriver); |
fe0cae24 | 85 | cleanupscreen(); |
b3a57661 | 86 | exit(0); |
7fc06086 | 87 | } |
c77f0542 | 88 | |
b3a57661 | 89 | choke() |
c77f0542 | 90 | { |
b3a57661 | 91 | leave(LEAVE_QUIT); |
c77f0542 CL |
92 | } |
93 | ||
b3a57661 | 94 | child() |
c77f0542 | 95 | { |
b3a57661 EW |
96 | union wait status; |
97 | int pid; | |
c77f0542 | 98 | |
b3a57661 EW |
99 | (void) signal(SIGCHLD, SIG_IGN); |
100 | do { | |
3d66e5da | 101 | pid = wait3(&status, WNOHANG, (struct rusage *)0); |
b3a57661 | 102 | if (pid < 0 || pid > 0 && !WIFSTOPPED(status)) |
6c9d2a3c | 103 | hasdriver = 0; |
3d66e5da | 104 | } while (pid > 0); |
b3a57661 | 105 | (void) signal(SIGCHLD, child); |
c77f0542 | 106 | } |