X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/8d2dd1244517d9cf4b4e1fd9a4914c5496e8dfac..31f3bac6b88bfb55f83358b8a827924631f828ea:/wump/wump.c diff --git a/wump/wump.c b/wump/wump.c index 1e3de3b8..c1918920 100644 --- a/wump/wump.c +++ b/wump/wump.c @@ -1,4 +1,4 @@ -/* $NetBSD: wump.c,v 1.5 1997/10/12 03:36:42 lukem Exp $ */ +/* $NetBSD: wump.c,v 1.12 1999/09/12 09:02:24 jsm Exp $ */ /* * Copyright (c) 1989, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ #if 0 static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: wump.c,v 1.5 1997/10/12 03:36:42 lukem Exp $"); +__RCSID("$NetBSD: wump.c,v 1.12 1999/09/12 09:02:24 jsm Exp $"); #endif #endif /* not lint */ @@ -57,11 +57,14 @@ __RCSID("$NetBSD: wump.c,v 1.5 1997/10/12 03:36:42 lukem Exp $"); * would care to remember. */ +#include #include #include +#include #include #include #include +#include #include #include "pathnames.h" @@ -133,7 +136,7 @@ void pit_survive __P((void)); int shoot __P((char *)); void shoot_self __P((void)); int take_action __P((void)); -void usage __P((void)); +void usage __P((void)) __attribute__((__noreturn__)); void wump_kill __P((void)); int wump_nearby __P((void)); @@ -144,6 +147,9 @@ main(argc, argv) { int c; + /* Revoke setgid privileges */ + setregid(getgid(), getgid()); + #ifdef DEBUG while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != -1) #else @@ -377,7 +383,7 @@ move_to(room_number) wump_kill(); return(1); } - if (cave[next_room].has_a_pit) + if (cave[next_room].has_a_pit) { if (random() % 12 < 2) { pit_survive(); return(0); @@ -385,6 +391,7 @@ move_to(room_number) pit_kill(); return(1); } + } if (cave[next_room].has_a_bat) { (void)printf( @@ -420,13 +427,14 @@ shoot(room_list) */ arrow_location = player_loc; for (roomcnt = 1;; ++roomcnt, room_list = NULL) { - if (!(p = strtok(room_list, " \t\n"))) + if (!(p = strtok(room_list, " \t\n"))) { if (roomcnt == 1) { (void)printf( "The arrow falls to the ground at your feet!\n"); return(0); } else break; + } if (roomcnt > 5) { (void)printf( "The arrow wavers in its flight and and can go no further!\n"); @@ -716,13 +724,16 @@ int int_compare(a, b) const void *a, *b; { - return(*(int *)a < *(int *)b ? -1 : 1); + return(*(const int *)a < *(const int *)b ? -1 : 1); } void instructions() { - char buf[120], *p; + const char *pager; + pid_t pid; + int status; + int fd; /* * read the instructions file, if needed, and show the user how to @@ -738,12 +749,26 @@ puff of greasy black smoke! (poof)\n"); return; } - if (!(p = getenv("PAGER")) || - strlen(p) > sizeof(buf) + strlen(_PATH_WUMPINFO) + 5) - p = _PATH_PAGER; - - (void)sprintf(buf, "%s %s", p, _PATH_WUMPINFO); - (void)system(buf); + if (!isatty(STDOUT_FILENO)) + pager = "cat"; + else { + if (!(pager = getenv("PAGER")) || (*pager == 0)) + pager = _PATH_PAGER; + } + switch (pid = fork()) { + case 0: /* child */ + if ((fd = open(_PATH_WUMPINFO, O_RDONLY)) == -1) + err(1, "open %s", _PATH_WUMPINFO); + if (dup2(fd, STDIN_FILENO) == -1) + err(1, "dup2"); + (void)execl("/bin/sh", "sh", "-c", pager, NULL); + err(1, "exec sh -c %s", pager); + case -1: + err(1, "fork"); + default: + (void)waitpid(pid, &status, 0); + break; + } } void