From 2f7617b1f7eadb18a344fc09f8f6c50752a37369 Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 14 Jan 2015 17:45:25 +0000 Subject: [PATCH] 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. --- usr.bin/mandoc/mandoc.h | 9 +------- usr.bin/mandoc/read.c | 51 +++++++++++++---------------------------- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index bcf99b2d2a8..5b792373654 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.119 2014/12/16 23:44:16 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.120 2015/01/14 17:45:25 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -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 }; diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index ba26fe8784c..ebb47034fbe 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read.c,v 1.81 2014/12/28 14:39:08 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.82 2015/01/14 17:45:25 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010-2014 Ingo Schwarze + * Copyright (c) 2010-2015 Ingo Schwarze * Copyright (c) 2010, 2012 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -215,16 +215,9 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { ".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] = { @@ -605,11 +598,8 @@ read_whole_file(struct mparse *curp, const char *file, int fd, ssize_t ssz; 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); } /* @@ -661,12 +651,8 @@ read_whole_file(struct mparse *curp, const char *file, int fd, 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; } @@ -830,26 +816,23 @@ mparse_open(struct mparse *curp, int *fd, const char *file) /* 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]; @@ -878,10 +861,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, -- 2.20.1