source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Simplify handling of system errors: just exit(3).
Date: Wed, 14 Jan 2015 12:49:45 -0500 (EST)	[thread overview]
Message-ID: <8130939501712502207.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Simplify handling of system errors: just exit(3).
We already do the same for malloc(3) failure.
The is no virtue in trying to survive failure of fork(2) and the like.

Modified Files:
--------------
    mdocml:
        mandoc.h
        read.c

Revision Data
-------------
Index: read.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/read.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -Lread.c -Lread.c -u -p -r1.106 -r1.107
--- read.c
+++ read.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -220,16 +220,9 @@ static	const char * const	mandocerrs[MAN
 	".so request failed",
 
 	/* system errors */
-	"cannot dup file descriptor",
-	"cannot exec",
 	"gunzip failed with code",
-	"cannot fork",
 	NULL,
-	"cannot open pipe",
-	"cannot read file",
 	"gunzip died from signal",
-	"cannot stat file",
-	"wait failed",
 };
 
 static	const char * const	mandoclevels[MANDOCLEVEL_MAX] = {
@@ -611,11 +604,8 @@ read_whole_file(struct mparse *curp, con
 #if HAVE_MMAP
 	struct stat	 st;
 	if (-1 == fstat(fd, &st)) {
-		curp->file_status = MANDOCLEVEL_SYSERR;
-		if (curp->mmsg)
-			(*curp->mmsg)(MANDOCERR_SYSSTAT, curp->file_status,
-			    file, 0, 0, strerror(errno));
-		return(0);
+		perror(file);
+		exit((int)MANDOCLEVEL_SYSERR);
 	}
 
 	/*
@@ -668,12 +658,8 @@ read_whole_file(struct mparse *curp, con
 			return(1);
 		}
 		if (ssz == -1) {
-			curp->file_status = MANDOCLEVEL_SYSERR;
-			if (curp->mmsg)
-				(*curp->mmsg)(MANDOCERR_SYSREAD,
-				    curp->file_status, file, 0, 0,
-				    strerror(errno));
-			break;
+			perror(file);
+			exit((int)MANDOCLEVEL_SYSERR);
 		}
 		off += (size_t)ssz;
 	}
@@ -852,26 +838,23 @@ mparse_open(struct mparse *curp, int *fd
 	/* Run gunzip(1). */
 
 	if (pipe(pfd) == -1) {
-		err = MANDOCERR_SYSPIPE;
-		goto out;
+		perror("pipe");
+		exit((int)MANDOCLEVEL_SYSERR);
 	}
 
 	switch (curp->child = fork()) {
 	case -1:
-		err = MANDOCERR_SYSFORK;
-		close(pfd[0]);
-		close(pfd[1]);
-		pfd[1] = -1;
-		break;
+		perror("fork");
+		exit((int)MANDOCLEVEL_SYSERR);
 	case 0:
 		close(pfd[0]);
 		if (dup2(pfd[1], STDOUT_FILENO) == -1) {
-			err = MANDOCERR_SYSDUP;
-			break;
+			perror("dup");
+			exit((int)MANDOCLEVEL_SYSERR);
 		}
 		execlp("gunzip", "gunzip", "-c", file, NULL);
-		err = MANDOCERR_SYSEXEC;
-		break;
+		perror("exec");
+		exit((int)MANDOCLEVEL_SYSERR);
 	default:
 		close(pfd[1]);
 		*fd = pfd[0];
@@ -900,10 +883,8 @@ mparse_wait(struct mparse *curp)
 		return(MANDOCLEVEL_OK);
 
 	if (waitpid(curp->child, &status, 0) == -1) {
-		mandoc_msg(MANDOCERR_SYSWAIT, curp, 0, 0,
-		    strerror(errno));
-		curp->file_status = MANDOCLEVEL_SYSERR;
-		return(curp->file_status);
+		perror("wait");
+		exit((int)MANDOCLEVEL_SYSERR);
 	}
 	if (WIFSIGNALED(status)) {
 		mandoc_vmsg(MANDOCERR_SYSSIG, curp, 0, 0,
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.h,v
retrieving revision 1.177
retrieving revision 1.178
diff -Lmandoc.h -Lmandoc.h -u -p -r1.177 -r1.178
--- mandoc.h
+++ mandoc.h
@@ -177,16 +177,9 @@ enum	mandocerr {
 
 	/* ===== system errors ===== */
 
-	MANDOCERR_SYSDUP, /* cannot dup file descriptor */
-	MANDOCERR_SYSEXEC, /* cannot exec */
 	MANDOCERR_SYSEXIT, /* gunzip failed with code */
-	MANDOCERR_SYSFORK, /* cannot fork */
 	MANDOCERR_SYSOPEN, /* cannot open file */
-	MANDOCERR_SYSPIPE, /* cannot open pipe */
-	MANDOCERR_SYSREAD, /* cannot read file */
 	MANDOCERR_SYSSIG, /* gunzip died from signal */
-	MANDOCERR_SYSSTAT, /* cannot stat file */
-	MANDOCERR_SYSWAIT, /* wait failed */
 
 	MANDOCERR_MAX
 };
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-01-14 17:49 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=8130939501712502207.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).