Subject: bin/7986: [PATCH] Fish pager handling
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 07/14/1999 10:32:04
>Number:         7986
>Category:       bin
>Synopsis:       [PATCH] Fish pager handling
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 14 10:05:01 1999
>Last-Modified:
>Originator:     Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1999-06-28
>Environment:
[
System: Linux decomino 2.2.10 #1 Mon Jun 14 07:48:53 UTC 1999 i686 unknown
Architecture: i686
]
>Description:

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.

>How-To-Repeat:

>Fix:

diff -ruN fish/fish.c fish+/fish.c
--- fish/fish.c	Mon Jun 28 23:56:35 1999
+++ fish+/fish.c	Wed Jul 14 15:57:16 1999
@@ -104,6 +104,8 @@
 {
 	int ch, move;
 
+	setgid(getgid());
+
 	while ((ch = getopt(argc, argv, "p")) != -1)
 		switch(ch) {
 		case 'p':
@@ -450,6 +452,8 @@
 {
 	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 @@
 
 	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");
>Audit-Trail:
>Unformatted: