summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/main.c38
-rw-r--r--usr.bin/mandoc/manconf.h4
-rw-r--r--usr.bin/mandoc/manpath.c29
-rw-r--r--usr.bin/mandoc/term_tag.c57
-rw-r--r--usr.bin/mandoc/term_tag.h8
5 files changed, 97 insertions, 39 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 34aa1e9382c..52c961d966a 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.254 2020/07/20 14:25:22 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.255 2020/07/21 15:08:48 schwarze Exp $ */
/*
* Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -152,7 +152,7 @@ main(int argc, char *argv[])
strcmp(progname, BINM_MAKEWHATIS) == 0)
return mandocdb(argc, argv);
- 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();
}
@@ -355,7 +355,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 &&
@@ -368,12 +370,16 @@ main(int argc, char *argv[])
conf.output.indent = 3;
}
- 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();
}
/* Parse arguments. */
@@ -620,7 +626,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)
@@ -815,7 +823,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)
diff --git a/usr.bin/mandoc/manconf.h b/usr.bin/mandoc/manconf.h
index 4cc623fac01..5073121b124 100644
--- a/usr.bin/mandoc/manconf.h
+++ b/usr.bin/mandoc/manconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: manconf.h,v 1.8 2020/04/02 22:10:27 schwarze Exp $ */
+/* $OpenBSD: manconf.h,v 1.9 2020/07/21 15:08:49 schwarze Exp $ */
/*
* Copyright (c) 2011,2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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;
diff --git a/usr.bin/mandoc/manpath.c b/usr.bin/mandoc/manpath.c
index dcd12a05a49..4032624b78c 100644
--- a/usr.bin/mandoc/manpath.c
+++ b/usr.bin/mandoc/manpath.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: manpath.c,v 1.28 2020/02/10 14:42:03 schwarze Exp $ */
+/* $OpenBSD: manpath.c,v 1.29 2020/07/21 15:08:49 schwarze Exp $ */
/*
* Copyright (c) 2011,2014,2015,2017-2019 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -226,7 +226,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]);
@@ -247,11 +248,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;
}
@@ -315,15 +316,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:
diff --git a/usr.bin/mandoc/term_tag.c b/usr.bin/mandoc/term_tag.c
index 1c67dcc1703..86ad01ed65d 100644
--- a/usr.bin/mandoc/term_tag.c
+++ b/usr.bin/mandoc/term_tag.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: term_tag.c,v 1.4 2020/04/18 20:28:46 schwarze Exp $ */
+/* $OpenBSD: term_tag.c,v 1.5 2020/07/21 15:08:49 schwarze Exp $ */
/*
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <errno.h>
+#include <fcntl.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
@@ -44,7 +45,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. */
@@ -81,19 +82,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));
@@ -173,11 +198,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';
}
diff --git a/usr.bin/mandoc/term_tag.h b/usr.bin/mandoc/term_tag.h
index 62be2d31bea..fc692d7b5ec 100644
--- a/usr.bin/mandoc/term_tag.h
+++ b/usr.bin/mandoc/term_tag.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: term_tag.h,v 1.2 2020/04/02 22:10:27 schwarze Exp $ */
+/* $OpenBSD: term_tag.h,v 1.3 2020/07/21 15:08:49 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);