diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-17 08:21:45 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-17 08:21:45 +0000 |
commit | 78efbbbea135cfd695e1ed7ac8b147d138c59631 (patch) | |
tree | 3272d9d8c1c8074258f21f267d74485d0344df83 | |
parent | c9d313b7b9aafe238f164b534082548d29ac380d (diff) |
move gunk out of signal handlers, now safe
-rw-r--r-- | games/worm/worm.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/games/worm/worm.c b/games/worm/worm.c index 3a87711bb6f..06fd29cad6b 100644 --- a/games/worm/worm.c +++ b/games/worm/worm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: worm.c,v 1.13 2001/09/03 18:04:08 pjanzen Exp $ */ +/* $OpenBSD: worm.c,v 1.14 2001/11/17 08:21:44 deraadt Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: worm.c,v 1.13 2001/09/03 18:04:08 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: worm.c,v 1.14 2001/11/17 08:21:44 deraadt Exp $"; #endif #endif /* not lint */ @@ -85,6 +85,9 @@ int visible_len; int lastch; char outbuf[BUFSIZ]; +int wantleave; +int wantsuspend; + void crash __P((void)); void display __P((struct body *, char)); void leave __P((int)); @@ -145,6 +148,23 @@ main(argc, argv) prize(); /* Put up a goal */ while(1) { + if (wantleave) { + endwin(); /* XXX signal race */ + exit(0); + } + if (wantsuspend) { + move(LINES-1, 0); + refresh(); + endwin(); + fflush(stdout); + kill(getpid(), SIGSTOP); + signal(SIGTSTP, suspend); + cbreak(); + noecho(); + setup(); + wantsuspend = 0; + } + if (running) { running--; @@ -210,8 +230,7 @@ void leave(dummy) int dummy; { - endwin(); - exit(0); + wantleave = 1; } int @@ -356,15 +375,7 @@ void suspend(dummy) int dummy; { - move(LINES-1, 0); - refresh(); - endwin(); - fflush(stdout); - kill(getpid(), SIGSTOP); - signal(SIGTSTP, suspend); - cbreak(); - noecho(); - setup(); + wantsuspend = 1; } void |