diff options
author | steve <steve@FreeBSD.org> | 1999-04-19 03:59:02 +0000 |
---|---|---|
committer | steve <steve@FreeBSD.org> | 1999-04-19 03:59:02 +0000 |
commit | d59a3ca336bac3dac6ad8918ff6cb28fcbbba718 (patch) | |
tree | c2b57d23128f242645f8e3e16274a587229383ec /games/wump/wump.c | |
parent | 390eb1b3d201760a5e8b76e2431c1f667648718f (diff) | |
download | FreeBSD-src-d59a3ca336bac3dac6ad8918ff6cb28fcbbba718.zip FreeBSD-src-d59a3ca336bac3dac6ad8918ff6cb28fcbbba718.tar.gz |
Merge a bunch of cleanups from NetBSD.
PR: 8083
Submitted by: Stephen J. Roznowski <sjr@home.net>
Obtained from: a whole slew of NetBSD PRs
Diffstat (limited to 'games/wump/wump.c')
-rw-r--r-- | games/wump/wump.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/games/wump/wump.c b/games/wump/wump.c index 753375c..7418591 100644 --- a/games/wump/wump.c +++ b/games/wump/wump.c @@ -51,8 +51,10 @@ static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93"; * would care to remember. */ +#include <err.h> #include <sys/types.h> #include <sys/file.h> +#include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -679,7 +681,10 @@ int_compare(a, b) instructions() { - char buf[120], *p, *getenv(); + const char *pager; + pid_t pid; + int status; + int fd; /* * read the instructions file, if needed, and show the user how to @@ -695,12 +700,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(1)) + 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, 0) == -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; + } } usage() |