summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c36
-rw-r--r--manconf.h2
-rw-r--r--manpath.c27
-rw-r--r--term_tag.c55
-rw-r--r--term_tag.h6
5 files changed, 92 insertions, 34 deletions
diff --git a/main.c b/main.c
index 33e921d0..0f32a644 100644
--- a/main.c
+++ b/main.c
@@ -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)
diff --git a/manconf.h b/manconf.h
index 34ee6201..c84409d7 100644
--- a/manconf.h
+++ b/manconf.h
@@ -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/manpath.c b/manpath.c
index a91a6e4e..545784cd 100644
--- a/manpath.c
+++ b/manpath.c
@@ -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:
diff --git a/term_tag.c b/term_tag.c
index 9386288e..968f88a0 100644
--- a/term_tag.c
+++ b/term_tag.c
@@ -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';
}
diff --git a/term_tag.h b/term_tag.h
index 676a0008..7009d4c4 100644
--- a/term_tag.h
+++ b/term_tag.h
@@ -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);