diff options
author | 2001-11-18 23:53:29 +0000 | |
---|---|---|
committer | 2001-11-18 23:53:29 +0000 | |
commit | 5029f74faeb82116c22cfdaff7fe3c984792b9b0 (patch) | |
tree | eda19a6ceb5def4f811f401dbcd3498283b387bd | |
parent | After a simplistic rewrite, signal flags were not being noticed until a (diff) | |
download | wireguard-openbsd-5029f74faeb82116c22cfdaff7fe3c984792b9b0.tar.xz wireguard-openbsd-5029f74faeb82116c22cfdaff7fe3c984792b9b0.zip |
move racey shit out of signal handler
-rw-r--r-- | games/snake/snake.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/games/snake/snake.c b/games/snake/snake.c index d5a774055a6..e05bfd8f3d0 100644 --- a/games/snake/snake.c +++ b/games/snake/snake.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snake.c,v 1.3 2001/02/18 16:03:02 pjanzen Exp $ */ +/* $OpenBSD: snake.c,v 1.4 2001/11/18 23:53:29 deraadt Exp $ */ /* $NetBSD: snake.c,v 1.8 1995/04/29 00:06:41 mycroft Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94"; #else -static char rcsid[] = "$OpenBSD: snake.c,v 1.3 2001/02/18 16:03:02 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: snake.c,v 1.4 2001/11/18 23:53:29 deraadt Exp $"; #endif #endif /* not lint */ @@ -146,6 +146,7 @@ void winnings __P((int)); void logit __P((char *)); #endif +int wantstop; int main(argc, argv) @@ -155,6 +156,7 @@ main(argc, argv) int ch, i; char *p, **av; time_t tv; + struct sigaction sa; /* don't create the score file if it doesn't exist. */ rawscores = open(_PATH_RAWSCORES, O_RDWR, 0664); @@ -250,7 +252,10 @@ main(argc, argv) i += 2; chunk = (675.0 / (i + 6)) + 2.5; /* min screen edge */ - signal(SIGINT, stop); + memset(&sa, 0, sizeof sa); + sigemptyset(&sa.sa_mask); + sa.sa_handler = stop; + sigaction(SIGINT, &sa, NULL); snrand(&finish); snrand(&you); @@ -274,6 +279,12 @@ mainloop() int repeat = 1; for (;;) { + if (wantstop) { + endwin(); + length(moves); + exit(0); + } + /* Highlight you, not left & above */ move(you.line + 1, you.col + 1); refresh(); @@ -953,10 +964,7 @@ void stop(dummy) int dummy; { - signal(SIGINT, SIG_IGN); - endwin(); - length(moves); - exit(0); + wantstop = 1; } void |