diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2020-07-21 15:10:01 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2020-07-21 15:10:01 +0000 |
commit | 34c3fd437f1b1a9f91c688bf395a99c631b642ed (patch) | |
tree | 457254f96054c09e8e8c023fc4e684b34c589021 | |
parent | eb396f5b0bb17fecfc3db0045d2979fa42d4478d (diff) | |
download | mandoc-34c3fd437f1b1a9f91c688bf395a99c631b642ed.tar.gz mandoc-34c3fd437f1b1a9f91c688bf395a99c631b642ed.tar.zst mandoc-34c3fd437f1b1a9f91c688bf395a99c631b642ed.zip |
undocumented options -O outfilename and -O tagfilename
to support regression testing without a tty;
no user visible change intended
-rw-r--r-- | main.c | 38 | ||||
-rw-r--r-- | manconf.h | 2 | ||||
-rw-r--r-- | manpath.c | 29 | ||||
-rw-r--r-- | term_tag.c | 57 | ||||
-rw-r--r-- | term_tag.h | 8 |
5 files changed, 96 insertions, 38 deletions
@@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.351 2020/07/20 16:57:30 schwarze Exp $ */ +/* $Id: main.c,v 1.352 2020/07/21 15:10:01 schwarze Exp $ */ /* * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> @@ -165,7 +165,7 @@ main(int argc, char *argv[]) return mandocdb(argc, argv); #if HAVE_PLEDGE - if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) { + if (pledge("stdio rpath wpath cpath tmppath tty proc exec", NULL) == -1) { mandoc_msg(MANDOCERR_PLEDGE, 0, 0, "%s", strerror(errno)); return mandoc_msg_getrc(); } @@ -373,7 +373,9 @@ main(int argc, char *argv[]) if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST || - !isatty(STDOUT_FILENO)) + (conf.output.outfilename == NULL && + conf.output.tagfilename == NULL && + isatty(STDOUT_FILENO) == 0)) outst.use_pager = 0; if (outst.use_pager && @@ -387,12 +389,16 @@ main(int argc, char *argv[]) } #if HAVE_PLEDGE - if (outst.use_pager == 0) { - if (pledge("stdio rpath", NULL) == -1) { - mandoc_msg(MANDOCERR_PLEDGE, 0, 0, - "%s", strerror(errno)); - return mandoc_msg_getrc(); - } + if (outst.use_pager == 0) + c = pledge("stdio rpath", NULL); + else if (conf.output.outfilename != NULL || + conf.output.tagfilename != NULL) + c = pledge("stdio rpath wpath cpath", NULL); + else + c = pledge("stdio rpath tmppath tty proc exec", NULL); + if (c == -1) { + mandoc_msg(MANDOCERR_PLEDGE, 0, 0, "%s", strerror(errno)); + return mandoc_msg_getrc(); } #endif @@ -642,7 +648,9 @@ out: manconf_free(&conf); if (outst.tag_files != NULL) { - if (term_tag_close() != -1) + if (term_tag_close() != -1 && + conf.output.outfilename == NULL && + conf.output.tagfilename == NULL) run_pager(&outst, conf.output.tag); term_tag_unlink(); } else if (outst.had_output && outst.outtype != OUTT_LINT) @@ -837,7 +845,15 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir, if (outst->use_pager) { outst->use_pager = 0; - outst->tag_files = term_tag_init(); + outst->tag_files = term_tag_init(conf->output.outfilename, + conf->output.tagfilename); + if ((conf->output.outfilename != NULL || + conf->output.tagfilename != NULL) && + pledge("stdio rpath cpath", NULL) == -1) { + mandoc_msg(MANDOCERR_PLEDGE, 0, 0, + "%s", strerror(errno)); + exit(mandoc_msg_getrc()); + } } if (outst->had_output && outst->outtype <= OUTT_UTF8) { if (outst->outdata == NULL) @@ -31,9 +31,11 @@ struct manpaths { struct manoutput { char *includes; char *man; + char *outfilename; char *paper; char *style; char *tag; + char *tagfilename; size_t indent; size_t width; int fragment; @@ -1,4 +1,4 @@ -/* $Id: manpath.c,v 1.41 2020/02/10 14:42:10 schwarze Exp $ */ +/* $Id: manpath.c,v 1.42 2020/07/21 15:10:01 schwarze Exp $ */ /* * Copyright (c) 2011,2014,2015,2017-2019 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> @@ -224,7 +224,8 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) { const char *const toks[] = { "includes", "man", "paper", "style", "indent", "width", - "tag", "fragment", "mdoc", "noval", "toc" + "tag", "outfilename", "tagfilename", + "fragment", "mdoc", "noval", "toc" }; const size_t ntoks = sizeof(toks) / sizeof(toks[0]); @@ -245,11 +246,11 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) } } - if (tok < 6 && *cp == '\0') { + if (tok < 8 && *cp == '\0') { mandoc_msg(MANDOCERR_BADVAL_MISS, 0, 0, "-O %s=?", toks[tok]); return -1; } - if (tok > 6 && tok < ntoks && *cp != '\0') { + if (tok > 8 && tok < ntoks && *cp != '\0') { mandoc_msg(MANDOCERR_BADVAL, 0, 0, "-O %s=%s", toks[tok], cp); return -1; } @@ -313,15 +314,29 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) conf->tag = mandoc_strdup(cp); return 0; case 7: - conf->fragment = 1; + if (conf->outfilename != NULL) { + oldval = mandoc_strdup(conf->outfilename); + break; + } + conf->outfilename = mandoc_strdup(cp); return 0; case 8: - conf->mdoc = 1; + if (conf->tagfilename != NULL) { + oldval = mandoc_strdup(conf->tagfilename); + break; + } + conf->tagfilename = mandoc_strdup(cp); return 0; case 9: - conf->noval = 1; + conf->fragment = 1; return 0; case 10: + conf->mdoc = 1; + return 0; + case 11: + conf->noval = 1; + return 0; + case 12: conf->toc = 1; return 0; default: @@ -1,4 +1,4 @@ -/* $Id: term_tag.c,v 1.4 2020/04/18 20:40:10 schwarze Exp $ */ +/* $Id: term_tag.c,v 1.5 2020/07/21 15:10:01 schwarze Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -22,6 +22,7 @@ #include <sys/types.h> #include <errno.h> +#include <fcntl.h> #include <signal.h> #include <stddef.h> #include <stdio.h> @@ -46,7 +47,7 @@ static struct tag_files tag_files; * but for simplicity, create it anyway. */ struct tag_files * -term_tag_init(void) +term_tag_init(const char *outfilename, const char *tagfilename) { struct sigaction sa; int ofd; /* In /tmp/, dup(2)ed to stdout. */ @@ -83,19 +84,43 @@ term_tag_init(void) /* Create both temporary output files. */ - (void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX", - sizeof(tag_files.ofn)); - (void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX", - sizeof(tag_files.tfn)); - if ((ofd = mkstemp(tag_files.ofn)) == -1) { - mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, - "%s: %s", tag_files.ofn, strerror(errno)); - goto fail; + if (outfilename == NULL) { + (void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX", + sizeof(tag_files.ofn)); + if ((ofd = mkstemp(tag_files.ofn)) == -1) { + mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, + "%s: %s", tag_files.ofn, strerror(errno)); + goto fail; + } + } else { + (void)strlcpy(tag_files.ofn, outfilename, + sizeof(tag_files.ofn)); + unlink(outfilename); + ofd = open(outfilename, O_WRONLY | O_CREAT | O_EXCL, 0644); + if (ofd == -1) { + mandoc_msg(MANDOCERR_OPEN, 0, 0, + "%s: %s", outfilename, strerror(errno)); + goto fail; + } } - if ((tfd = mkstemp(tag_files.tfn)) == -1) { - mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, - "%s: %s", tag_files.tfn, strerror(errno)); - goto fail; + if (tagfilename == NULL) { + (void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX", + sizeof(tag_files.tfn)); + if ((tfd = mkstemp(tag_files.tfn)) == -1) { + mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, + "%s: %s", tag_files.tfn, strerror(errno)); + goto fail; + } + } else { + (void)strlcpy(tag_files.tfn, tagfilename, + sizeof(tag_files.tfn)); + unlink(tagfilename); + tfd = open(tagfilename, O_WRONLY | O_CREAT | O_EXCL, 0644); + if (tfd == -1) { + mandoc_msg(MANDOCERR_OPEN, 0, 0, + "%s: %s", tagfilename, strerror(errno)); + goto fail; + } } if ((tag_files.tfs = fdopen(tfd, "w")) == NULL) { mandoc_msg(MANDOCERR_FDOPEN, 0, 0, "%s", strerror(errno)); @@ -175,11 +200,11 @@ term_tag_unlink(void) getpgid(tc_pgid) == -1) (void)tcsetpgrp(STDOUT_FILENO, tag_files.tcpgid); } - if (*tag_files.ofn != '\0') { + if (strncmp(tag_files.ofn, "/tmp/man.", 9) == 0) { unlink(tag_files.ofn); *tag_files.ofn = '\0'; } - if (*tag_files.tfn != '\0') { + if (strncmp(tag_files.tfn, "/tmp/man.", 9) == 0) { unlink(tag_files.tfn); *tag_files.tfn = '\0'; } @@ -1,4 +1,4 @@ -/* $Id: term_tag.h,v 1.2 2020/04/02 22:12:55 schwarze Exp $ */ +/* $Id: term_tag.h,v 1.3 2020/07/21 15:10:01 schwarze Exp $ */ /* * Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -19,8 +19,8 @@ */ struct tag_files { - char ofn[20]; /* Output file name. */ - char tfn[20]; /* Tag file name. */ + char ofn[80]; /* Output file name. */ + char tfn[80]; /* Tag file name. */ FILE *tfs; /* Tag file object. */ int ofd; /* Original output file descriptor. */ pid_t tcpgid; /* Process group controlling the terminal. */ @@ -28,7 +28,7 @@ struct tag_files { }; -struct tag_files *term_tag_init(void); +struct tag_files *term_tag_init(const char *, const char *); void term_tag_write(struct roff_node *, size_t); int term_tag_close(void); void term_tag_unlink(void); |