summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-11-26 21:40:12 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-11-26 21:40:12 +0000
commit6d62f91ca09153085860e8ef685901d928cd18b3 (patch)
treec379d12fc5452792f0d0b2c69331e6d19b68b326
parent34b9f1984c0dc531d6656a31445bc2c592fca5de (diff)
Simplify the mparse_open()/mparse_wait() interface.
Don't bother the user with the PID of the child process, store it inside the opaque mparse handle.
-rw-r--r--usr.bin/mandoc/main.c12
-rw-r--r--usr.bin/mandoc/mandoc.h7
-rw-r--r--usr.bin/mandoc/mandocdb.c9
-rw-r--r--usr.bin/mandoc/read.c19
4 files changed, 21 insertions, 26 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index bd9e3a74e0c..17bbc2d3edc 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.107 2014/11/11 19:03:10 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.108 2014/11/26 21:40:11 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -107,7 +107,6 @@ main(int argc, char *argv[])
char sec;
enum mandoclevel rc;
enum outmode outmode;
- pid_t child_pid;
int fd;
int show_usage;
int use_pager;
@@ -375,8 +374,7 @@ main(int argc, char *argv[])
while (argc) {
if (resp != NULL) {
- rc = mparse_open(curp.mp, &fd, resp->file,
- &child_pid);
+ rc = mparse_open(curp.mp, &fd, resp->file);
if (fd == -1)
/* nothing */;
else if (resp->form & FORM_SRC) {
@@ -388,14 +386,12 @@ main(int argc, char *argv[])
synopsis_only);
resp++;
} else {
- rc = mparse_open(curp.mp, &fd, *argv++,
- &child_pid);
+ rc = mparse_open(curp.mp, &fd, *argv++);
if (fd != -1)
parse(&curp, fd, argv[-1], &rc);
}
- if (child_pid &&
- mparse_wait(curp.mp, child_pid) != MANDOCLEVEL_OK)
+ if (mparse_wait(curp.mp) != MANDOCLEVEL_OK)
rc = MANDOCLEVEL_SYSERR;
if (MANDOCLEVEL_OK != rc && curp.wstop)
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 8832b8db56e..5847732e443 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandoc.h,v 1.111 2014/10/30 00:05:02 schwarze Exp $ */
+/* $OpenBSD: mandoc.h,v 1.112 2014/11/26 21:40:11 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -436,8 +436,7 @@ struct mparse *mparse_alloc(int, enum mandoclevel, mandocmsg,
const struct mchars *, const char *);
void mparse_free(struct mparse *);
void mparse_keep(struct mparse *);
-enum mandoclevel mparse_open(struct mparse *, int *, const char *,
- pid_t *);
+enum mandoclevel mparse_open(struct mparse *, int *, const char *);
enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
void mparse_reset(struct mparse *);
void mparse_result(struct mparse *,
@@ -445,7 +444,7 @@ void mparse_result(struct mparse *,
const char *mparse_getkeep(const struct mparse *);
const char *mparse_strerror(enum mandocerr);
const char *mparse_strlevel(enum mandoclevel);
-enum mandoclevel mparse_wait(struct mparse *, pid_t);
+enum mandoclevel mparse_wait(struct mparse *);
__END_DECLS
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index 7d70644a5d2..27f50740366 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandocdb.c,v 1.124 2014/11/19 20:40:28 schwarze Exp $ */
+/* $OpenBSD: mandocdb.c,v 1.125 2014/11/26 21:40:11 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1074,7 +1074,6 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
struct man *man;
char *sodest;
char *cp;
- pid_t child_pid;
int fd;
unsigned int pslot;
enum mandoclevel lvl;
@@ -1102,9 +1101,8 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
mdoc = NULL;
man = NULL;
sodest = NULL;
- child_pid = 0;
- mparse_open(mp, &fd, mpage->mlinks->file, &child_pid);
+ mparse_open(mp, &fd, mpage->mlinks->file);
if (fd == -1) {
say(mpage->mlinks->file, "&open");
goto nextpage;
@@ -1221,8 +1219,7 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
dbadd(mpage, mc);
nextpage:
- if (child_pid &&
- mparse_wait(mp, child_pid) != MANDOCLEVEL_OK) {
+ if (mparse_wait(mp) != MANDOCLEVEL_OK) {
exitcode = (int)MANDOCLEVEL_SYSERR;
say(mpage->mlinks->file, "&wait gunzip");
}
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 3148c3612f5..ef369b30143 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.72 2014/11/01 06:02:43 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.73 2014/11/26 21:40:11 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -58,6 +58,7 @@ struct mparse {
int filenc; /* encoding of the current file */
int reparse_count; /* finite interp. stack */
int line; /* line number in the file */
+ pid_t child; /* the gunzip(1) process */
};
static void choose_parser(struct mparse *);
@@ -800,8 +801,7 @@ mparse_readfd(struct mparse *curp, int fd, const char *file)
}
enum mandoclevel
-mparse_open(struct mparse *curp, int *fd, const char *file,
- pid_t *child_pid)
+mparse_open(struct mparse *curp, int *fd, const char *file)
{
int pfd[2];
char *cp;
@@ -811,7 +811,7 @@ mparse_open(struct mparse *curp, int *fd, const char *file,
curp->file = file;
if ((cp = strrchr(file, '.')) == NULL ||
strcmp(cp + 1, "gz")) {
- *child_pid = 0;
+ curp->child = 0;
if ((*fd = open(file, O_RDONLY)) == -1) {
err = MANDOCERR_SYSOPEN;
goto out;
@@ -824,7 +824,7 @@ mparse_open(struct mparse *curp, int *fd, const char *file,
goto out;
}
- switch (*child_pid = fork()) {
+ switch (curp->child = fork()) {
case -1:
err = MANDOCERR_SYSFORK;
close(pfd[0]);
@@ -848,7 +848,7 @@ mparse_open(struct mparse *curp, int *fd, const char *file,
out:
*fd = -1;
- *child_pid = 0;
+ curp->child = 0;
curp->file_status = MANDOCLEVEL_SYSERR;
if (curp->mmsg)
(*curp->mmsg)(err, curp->file_status, file,
@@ -859,11 +859,14 @@ out:
}
enum mandoclevel
-mparse_wait(struct mparse *curp, pid_t child_pid)
+mparse_wait(struct mparse *curp)
{
int status;
- if (waitpid(child_pid, &status, 0) == -1) {
+ if (curp->child == 0)
+ return(MANDOCLEVEL_OK);
+
+ if (waitpid(curp->child, &status, 0) == -1) {
mandoc_msg(MANDOCERR_SYSWAIT, curp, 0, 0,
strerror(errno));
curp->file_status = MANDOCLEVEL_SYSERR;