X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/5a555a984855e94b0fc3c9154da6b65208ba2c70..31f3bac6b88bfb55f83358b8a827924631f828ea:/wump/wump.c?ds=inline diff --git a/wump/wump.c b/wump/wump.c index bcffa5eb..c1918920 100644 --- a/wump/wump.c +++ b/wump/wump.c @@ -1,4 +1,4 @@ -/* $NetBSD: wump.c,v 1.6 1998/08/30 09:19:41 veego 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.6 1998/08/30 09:19:41 veego 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.6 1998/08/30 09:19:41 veego 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 @@ -718,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 @@ -740,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