diff options
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | main.c | 10 | ||||
-rw-r--r-- | mandoc.3 | 10 | ||||
-rw-r--r-- | mandoc.h | 5 | ||||
-rw-r--r-- | mandocdb.c | 7 | ||||
-rw-r--r-- | read.c | 17 |
6 files changed, 20 insertions, 32 deletions
@@ -564,6 +564,9 @@ Several areas can be cleaned up to make mandoc even faster. These are * structural issues ************************************************************************ +- Use libz directly instead of forking gunzip(1). + Suggested by bapt at FreeBSD among others. + - We use the input line number at several places to distinguish same-line from different-line input. That plainly doesn't work with user-defined macros, leading to random breakage. @@ -115,7 +115,6 @@ main(int argc, char *argv[]) #endif enum mandoclevel rc; enum outmode outmode; - pid_t child_pid; int fd; int show_usage; int use_pager; @@ -388,8 +387,7 @@ main(int argc, char *argv[]) while (argc) { #if HAVE_SQLITE3 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) { @@ -403,14 +401,12 @@ main(int argc, char *argv[]) } else #endif { - 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) @@ -81,7 +81,6 @@ .Fa "struct mparse *parse" .Fa "int *fd" .Fa "const char *fname" -.Fa "pid_t *child_pid" .Fc .Ft "enum mandoclevel" .Fo mparse_readfd @@ -111,7 +110,6 @@ .Ft "enum mandoclevel" .Fo mparse_wait .Fa "struct mparse *parse" -.Fa "pid_t child_pid" .Fc .In sys/types.h .In mandoc.h @@ -404,14 +402,6 @@ or -1 on failure. It can be passed to .Fn mparse_readfd or used directly. -If applicable, return the -.Xr gunzip 1 -child process ID in -.Fa child_pid , -or otherwise 0. -If non-zero, it should be passed to -.Fn mparse_wait -after completing the parse sequence. Declared in .In mandoc.h , implemented in @@ -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 *); enum mandoclevel mparse_readmem(struct mparse *, const void *, size_t, const char *); @@ -447,7 +446,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 @@ -1084,7 +1084,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; @@ -1112,9 +1111,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; @@ -1231,8 +1229,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"); } @@ -64,6 +64,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 *); @@ -823,8 +824,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; @@ -834,7 +834,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; @@ -847,7 +847,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]); @@ -871,7 +871,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, @@ -882,11 +882,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; |