summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-03-17 07:32:22 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-03-17 07:32:22 +0000
commit653ac68a41ccb31f5d3a22958c3208b96b2d0dac (patch)
tree8cd5637683719d8e0095ef2c448f1e897a0d9530 /usr.bin
parent88d4b74065bfeccb2a8e52611110afdc7cc965d4 (diff)
When the user exits the pager before the pager has drained all input
from man(1), man(1) dies from SIGPIPE. Exiting man(1) is fine in this case, generating more output would be pointless, but without handling SIGPIPE, the exit code from man(1) was wrong and csh(1) printed an ugly message "Broken pipe". Fix this by handling SIGPIPE explicitly. Issue noticed by deraadt@.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/main.c15
-rw-r--r--usr.bin/mandoc/read.c4
2 files changed, 16 insertions, 3 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 876dfaad1d0..2a13145303a 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.130 2015/03/10 13:48:57 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.131 2015/03/17 07:32:21 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -26,6 +26,7 @@
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
+#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -85,6 +86,7 @@ static int fs_lookup(const struct manpaths *,
static void fs_search(const struct mansearch *,
const struct manpaths *, int, char**,
struct manpage **, size_t *);
+static void handle_sigpipe(int);
static int koptions(int *, char *);
int mandocdb(int, char**);
static int moptions(int *, char *);
@@ -102,6 +104,7 @@ static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
static char help_arg[] = "help";
static char *help_argv[] = {help_arg, NULL};
static const char *progname;
+static enum mandoclevel rc;
int
@@ -118,7 +121,7 @@ main(int argc, char *argv[])
size_t isec, i, sz;
int prio, best_prio, synopsis_only;
char sec;
- enum mandoclevel rc, rctmp;
+ enum mandoclevel rctmp;
enum outmode outmode;
int fd;
int show_usage;
@@ -915,6 +918,13 @@ mmsg(enum mandocerr t, enum mandoclevel lvl,
fputc('\n', stderr);
}
+static void
+handle_sigpipe(int signum)
+{
+
+ exit(rc);
+}
+
static pid_t
spawn_pager(void)
{
@@ -947,6 +957,7 @@ spawn_pager(void)
exit((int)MANDOCLEVEL_SYSERR);
}
close(fildes[1]);
+ signal(SIGPIPE, handle_sigpipe);
return(pager_pid);
}
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 9e33c1ed943..4f07bb117a7 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.106 2015/03/11 13:04:10 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.107 2015/03/17 07:32:21 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -25,6 +25,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -824,6 +825,7 @@ mparse_open(struct mparse *curp, int *fd, const char *file)
perror("dup");
exit((int)MANDOCLEVEL_SYSERR);
}
+ signal(SIGPIPE, SIG_DFL);
execlp("gunzip", "gunzip", "-c", file, NULL);
perror("exec");
exit((int)MANDOCLEVEL_SYSERR);