diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-03-10 03:00:49 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-03-10 03:00:49 +0000 |
commit | b5798eb6bbf22c2b3860aa142a1b88b7ed6f1cc9 (patch) | |
tree | d271df6133b70bc31605658b95a3f31da6f2a8d5 /usr.bin | |
parent | e3f4ca128fb06b86827b7b330a8d61df7e4252ce (diff) |
Fix a regression caused in rev. 1.118, reported by kristaps@:
When using a pager and the first manual shown is gzip'ed,
the gunzip(1) process ended up as a child of the pager process
such that the man(1) process couldn't wait for it, preventing
proper display of the manual.
Solve this by making the pager a child of the man(1) process
(instead of the other way round), which requires being a bit
more careful about properly closing file descriptors after use
and waiting for the pager before exiting man(1).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/main.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index d79e6cb8eb3..fd62433c6fd 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.128 2015/03/09 21:30:27 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.129 2015/03/10 03:00:48 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -19,6 +19,7 @@ #include <sys/types.h> #include <sys/param.h> /* MACHINE */ +#include <sys/wait.h> #include <assert.h> #include <ctype.h> @@ -458,6 +459,21 @@ out: free(defos); + /* + * Flush the output and signal end of file. + * If a pager is attached, it allows browsing to the end. + * Otherwise, it does no harm, we are about to exit anyway. + */ + + fclose(stdout); + + /* + * If we spawned a pager, wait for the user to close it. + * Otherwise, this call fails with no adverse effect. + */ + + wait(NULL); + return((int)rc); } @@ -926,18 +942,19 @@ spawn_pager(void) progname, strerror(errno)); exit((int)MANDOCLEVEL_SYSERR); case 0: + break; + default: close(fildes[0]); if (dup2(fildes[1], STDOUT_FILENO) == -1) { fprintf(stderr, "%s: dup output: %s\n", progname, strerror(errno)); exit((int)MANDOCLEVEL_SYSERR); } + close(fildes[1]); return; - default: - break; } - /* The original process becomes the pager. */ + /* The child process becomes the pager. */ close(fildes[1]); if (dup2(fildes[0], STDIN_FILENO) == -1) { @@ -945,6 +962,7 @@ spawn_pager(void) progname, strerror(errno)); exit((int)MANDOCLEVEL_SYSERR); } + close(fildes[0]); pager = getenv("MANPAGER"); if (pager == NULL || *pager == '\0') |