summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-12-20 21:27:52 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-12-20 21:27:52 +0000
commit599dd1f39442becfa0ec02a38ff27000a7dff829 (patch)
tree9d01347cf80b21b4eae0ebeccb4a24d2b76654c0 /usr.bin
parent0956a599119aef0b30ec6e41dee2cb94f503c2fb (diff)
Move the full responsibility for reporting open(2) errors from
mparse_open() to the caller. That is better because only the caller knows its preferred reporting method and format and only the caller has access to all the data that should be included - like the column number in .so processing or the current manpath in makewhatis(8). Moving the mandoc_msg() call out is possible because the caller can call strerror(3) just as easily as mparse_open() can. Move mandoc_msg_setinfilename() closer to the parsing of the file contents, to avoid problems *with* the file (like non-existence, lack of permissions, etc.) getting misreported as problems *in* the file. Fix the column number reported for .so failure: let it point to the beginning of the filename. Taken together, this prevents makewhatis(8) from spewing confusing messages about .so failures to stderr, a bug reported by Raf Czlonka <rczlonka at gmail dot com> on ports@. It also prevents mandoc(1) from issuing *two* messages for every single .so failure.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/main.c10
-rw-r--r--usr.bin/mandoc/read.c8
2 files changed, 10 insertions, 8 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 8fd47eb38f7..47c989073ad 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.216 2018/12/14 05:17:45 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.217 2018/12/20 21:27:51 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -480,7 +480,6 @@ main(int argc, char *argv[])
} else
thisarg = *argv;
- mandoc_msg_setinfilename(thisarg);
fd = mparse_open(curp.mp, thisarg);
if (fd != -1) {
if (use_pager) {
@@ -493,11 +492,13 @@ main(int argc, char *argv[])
conf.output.tag : *argv;
}
+ mandoc_msg_setinfilename(thisarg);
if (resp == NULL || resp->form == FORM_SRC)
parse(&curp, fd, thisarg);
else
passthrough(resp->file, fd,
conf.output.synopsisonly);
+ mandoc_msg_setinfilename(NULL);
if (ferror(stdout)) {
if (tag_files != NULL) {
@@ -515,8 +516,9 @@ main(int argc, char *argv[])
outdata_alloc(&curp);
terminal_sepline(curp.outdata);
}
- }
- mandoc_msg_setinfilename(NULL);
+ } else
+ mandoc_msg(MANDOCERR_FILE, 0, 0,
+ "%s", strerror(errno));
if (curp.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK)
break;
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 2cb4b29a478..dae214b2d51 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.178 2018/12/14 06:33:03 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.179 2018/12/20 21:27:51 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -370,8 +370,9 @@ rerun:
mparse_readfd(curp, fd, ln.buf + of);
close(fd);
} else {
- mandoc_msg(MANDOCERR_SO_FAIL, curp->line,
- pos, ".so %s", ln.buf + of);
+ mandoc_msg(MANDOCERR_SO_FAIL,
+ curp->line, of, ".so %s: %s",
+ ln.buf + of, strerror(errno));
ln.sz = mandoc_asprintf(&cp,
".sp\nSee the file %s.\n.sp",
ln.buf + of);
@@ -631,7 +632,6 @@ mparse_open(struct mparse *curp, const char *file)
/* Neither worked, give up. */
- mandoc_msg(MANDOCERR_FILE, 0, 0, "%s", strerror(errno));
return -1;
}