summaryrefslogtreecommitdiffstats
path: root/fish
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>1999-07-14 17:30:21 +0000
committerhubertf <hubertf@NetBSD.org>1999-07-14 17:30:21 +0000
commitb6a635e2fb9768460aff574e019ff51b14aab46d (patch)
treea4e4de71d5345ed9f277a0dab53d9c55800b35a1 /fish
parentb09314c8a14ae0411499270e4e0e63c98ef0fbc2 (diff)
downloadbsdgames-darwin-b6a635e2fb9768460aff574e019ff51b14aab46d.tar.gz
bsdgames-darwin-b6a635e2fb9768460aff574e019ff51b14aab46d.tar.zst
bsdgames-darwin-b6a635e2fb9768460aff574e019ff51b14aab46d.zip
This patch makes fish(6) honour PAGER for viewing the instructions.
The detailed behaviour follows POSIX.2. A similar patch for wump(6) which was accepted is in bin/6699. Fish does not need any setgid privileges it gets from dm, so this patch also moves the gid resetting earlier. Reported in PR 7986 by Joseph Myers <jsm28@cam.ac.uk>
Diffstat (limited to 'fish')
-rw-r--r--fish/fish.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/fish/fish.c b/fish/fish.c
index df12fe7e..3775e50f 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fish.c,v 1.7 1999/04/24 22:09:06 kristerw Exp $ */
+/* $NetBSD: fish.c,v 1.8 1999/07/14 17:30:21 hubertf Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fish.c,v 1.7 1999/04/24 22:09:06 kristerw Exp $");
+__RCSID("$NetBSD: fish.c,v 1.8 1999/07/14 17:30:21 hubertf Exp $");
#endif
#endif /* not lint */
@@ -104,6 +104,8 @@ main(argc, argv)
{
int ch, move;
+ setgid(getgid());
+
while ((ch = getopt(argc, argv, "p")) != -1)
switch(ch) {
case 'p':
@@ -450,6 +452,8 @@ instructions()
{
int input;
pid_t pid;
+ int fd;
+ const char *pager;
int status;
(void)printf("Would you like instructions (y or n)? ");
@@ -460,10 +464,18 @@ instructions()
switch (pid = fork()) {
case 0: /* child */
- (void)setuid(getuid());
- (void)setgid(getgid());
- (void)execl(_PATH_MORE, "more", _PATH_INSTR, NULL);
- err(1, "%s %s", _PATH_MORE, _PATH_INSTR);
+ if (!isatty(1))
+ pager = "cat";
+ else {
+ if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_MORE;
+ }
+ if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1)
+ err(1, "open %s", _PATH_INSTR);
+ if (dup2(fd, 0) == -1)
+ err(1, "dup2");
+ (void)execl("/bin/sh", "sh", "-c", pager, NULL);
+ err(1, "exec sh -c %s", pager);
/*NOTREACHED*/
case -1:
err(1, "fork");