source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: When the user exits the pager before the pager has drained all
Date: Tue, 17 Mar 2015 02:33:37 -0500 (EST)	[thread overview]
Message-ID: <2066483516209013163.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
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@.

Modified Files:
--------------
    mdocml:
        main.c
        read.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/main.c,v
retrieving revision 1.225
retrieving revision 1.226
diff -Lmain.c -Lmain.c -u -p -r1.225 -r1.226
--- main.c
+++ main.c
@@ -27,6 +27,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <glob.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -92,6 +93,7 @@ static	int		  fs_lookup(const struct man
 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 *);
 #if HAVE_SQLITE3
 int			  mandocdb(int, char**);
@@ -111,6 +113,7 @@ static	const int sec_prios[] = {1, 4, 5,
 static	char		  help_arg[] = "help";
 static	char		 *help_argv[] = {help_arg, NULL};
 static	const char	 *progname;
+static	enum mandoclevel  rc;
 
 
 int
@@ -127,7 +130,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;
@@ -940,6 +943,13 @@ mmsg(enum mandocerr t, enum mandoclevel 
 	fputc('\n', stderr);
 }
 
+static void
+handle_sigpipe(int signum)
+{
+
+	exit(rc);
+}
+
 static pid_t
 spawn_pager(void)
 {
@@ -972,6 +982,7 @@ spawn_pager(void)
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
 		close(fildes[1]);
+		signal(SIGPIPE, handle_sigpipe);
 		return(pager_pid);
 	}
 
Index: read.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/read.c,v
retrieving revision 1.131
retrieving revision 1.132
diff -Lread.c -Lread.c -u -p -r1.131 -r1.132
--- read.c
+++ read.c
@@ -29,6 +29,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -846,6 +847,7 @@ mparse_open(struct mparse *curp, int *fd
 			perror("dup");
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
+		signal(SIGPIPE, SIG_DFL);
 		execlp("gunzip", "gunzip", "-c", file, NULL);
 		perror("exec");
 		exit((int)MANDOCLEVEL_SYSERR);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-03-17  7:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2066483516209013163.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).