=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.259 retrieving revision 1.263 diff -u -p -r1.259 -r1.263 --- mandoc/main.c 2015/11/20 21:59:54 1.259 +++ mandoc/main.c 2016/01/16 22:30:33 1.263 @@ -1,7 +1,7 @@ -/* $Id: main.c,v 1.259 2015/11/20 21:59:54 schwarze Exp $ */ +/* $Id: main.c,v 1.263 2016/01/16 22:30:33 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze + * Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -126,7 +126,6 @@ main(int argc, char *argv[]) size_t isec, i, sz; int prio, best_prio; char sec; - enum mandoclevel rctmp; enum outmode outmode; int fd; int show_usage; @@ -299,8 +298,9 @@ main(int argc, char *argv[]) use_pager = 0; #if HAVE_PLEDGE - if (!use_pager && pledge("stdio rpath flock", NULL) == -1) - err((int)MANDOCLEVEL_SYSERR, "pledge"); + if (!use_pager) + if (pledge("stdio rpath flock", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); #endif /* Parse arguments. */ @@ -430,9 +430,13 @@ main(int argc, char *argv[]) /* mandoc(1) */ #if HAVE_PLEDGE - if (pledge(use_pager ? "stdio rpath tmppath tty proc exec" : - "stdio rpath", NULL) == -1) - err((int)MANDOCLEVEL_SYSERR, "pledge"); + if (use_pager) { + if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); + } else { + if (pledge("stdio rpath", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); + } #endif if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) @@ -454,11 +458,7 @@ main(int argc, char *argv[]) } while (argc > 0) { - rctmp = mparse_open(curp.mp, &fd, - resp != NULL ? resp->file : *argv); - if (rc < rctmp) - rc = rctmp; - + fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv); if (fd != -1) { if (use_pager) { tag_files = tag_init(); @@ -477,7 +477,8 @@ main(int argc, char *argv[]) if (argc > 1 && curp.outtype <= OUTT_UTF8) ascii_sepline(curp.outdata); - } + } else if (rc < MANDOCLEVEL_ERROR) + rc = MANDOCLEVEL_ERROR; if (MANDOCLEVEL_OK != rc && curp.wstop) break; @@ -719,9 +720,11 @@ parse(struct curparse *curp, int fd, const char *file) /* Begin by parsing the file itself. */ assert(file); - assert(fd >= -1); + assert(fd >= 0); rctmp = mparse_readfd(curp->mp, fd, file); + if (fd != STDIN_FILENO) + close(fd); if (rc < rctmp) rc = rctmp;