]>
git.cameronkatri.com Git - mandoc.git/blob - main.c
1 /* $Id: main.c,v 1.266 2016/05/18 22:36:00 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
22 #include <sys/param.h> /* MACHINE */
41 #include "mandoc_aux.h"
49 #include "mansearch.h"
51 #if !defined(__GNUC__) || (__GNUC__ < 2)
53 # define __attribute__(x)
55 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
67 OUTT_ASCII
= 0, /* -Tascii */
68 OUTT_LOCALE
, /* -Tlocale */
69 OUTT_UTF8
, /* -Tutf8 */
70 OUTT_TREE
, /* -Ttree */
72 OUTT_HTML
, /* -Thtml */
73 OUTT_LINT
, /* -Tlint */
80 enum mandoclevel wlevel
; /* ignore messages below this */
81 int wstop
; /* stop after a file with a warning */
82 enum outt outtype
; /* which output to use */
83 void *outdata
; /* data for output */
84 struct manoutput
*outopts
; /* output options */
87 static int fs_lookup(const struct manpaths
*,
88 size_t ipath
, const char *,
89 const char *, const char *,
90 struct manpage
**, size_t *);
91 static void fs_search(const struct mansearch
*,
92 const struct manpaths
*, int, char**,
93 struct manpage
**, size_t *);
94 static int koptions(int *, char *);
96 int mandocdb(int, char**);
98 static int moptions(int *, char *);
99 static void mmsg(enum mandocerr
, enum mandoclevel
,
100 const char *, int, int, const char *);
101 static void parse(struct curparse
*, int, const char *);
102 static void passthrough(const char *, int, int);
103 static pid_t
spawn_pager(struct tag_files
*);
104 static int toptions(struct curparse
*, char *);
105 static void usage(enum argmode
) __attribute__((noreturn
));
106 static int woptions(struct curparse
*, char *);
108 static const int sec_prios
[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
109 static char help_arg
[] = "help";
110 static char *help_argv
[] = {help_arg
, NULL
};
111 static enum mandoclevel rc
;
115 main(int argc
, char *argv
[])
118 struct curparse curp
;
119 struct mansearch search
;
120 struct tag_files
*tag_files
;
121 const char *progname
;
125 struct manpage
*res
, *resp
;
126 char *conf_file
, *defpaths
;
130 enum outmode outmode
;
137 pid_t pager_pid
, tc_pgid
, man_pgid
, pid
;
140 progname
= getprogname();
143 progname
= mandoc_strdup("mandoc");
144 else if ((progname
= strrchr(argv
[0], '/')) == NULL
)
148 setprogname(progname
);
152 if (strncmp(progname
, "mandocdb", 8) == 0 ||
153 strcmp(progname
, BINM_MAKEWHATIS
) == 0)
154 return mandocdb(argc
, argv
);
158 if (pledge("stdio rpath tmppath tty proc exec flock", NULL
) == -1)
159 err((int)MANDOCLEVEL_SYSERR
, "pledge");
162 /* Search options. */
164 memset(&conf
, 0, sizeof(conf
));
165 conf_file
= defpaths
= NULL
;
168 memset(&search
, 0, sizeof(struct mansearch
));
169 search
.outkey
= "Nd";
171 if (strcmp(progname
, BINM_MAN
) == 0)
172 search
.argmode
= ARG_NAME
;
173 else if (strcmp(progname
, BINM_APROPOS
) == 0)
174 search
.argmode
= ARG_EXPR
;
175 else if (strcmp(progname
, BINM_WHATIS
) == 0)
176 search
.argmode
= ARG_WORD
;
177 else if (strncmp(progname
, "help", 4) == 0)
178 search
.argmode
= ARG_NAME
;
180 search
.argmode
= ARG_FILE
;
182 /* Parser and formatter options. */
184 memset(&curp
, 0, sizeof(struct curparse
));
185 curp
.outtype
= OUTT_LOCALE
;
186 curp
.wlevel
= MANDOCLEVEL_BADARG
;
187 curp
.outopts
= &conf
.output
;
188 options
= MPARSE_SO
| MPARSE_UTF8
| MPARSE_LATIN1
;
194 outmode
= OUTMODE_DEF
;
196 while (-1 != (c
= getopt(argc
, argv
,
197 "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
200 outmode
= OUTMODE_ALL
;
209 search
.argmode
= ARG_WORD
;
212 conf
.output
.synopsisonly
= 1;
214 outmode
= OUTMODE_ALL
;
217 if (strncmp(optarg
, "os=", 3)) {
218 warnx("-I %s: Bad argument", optarg
);
219 return (int)MANDOCLEVEL_BADARG
;
222 warnx("-I %s: Duplicate argument", optarg
);
223 return (int)MANDOCLEVEL_BADARG
;
225 defos
= mandoc_strdup(optarg
+ 3);
228 outmode
= OUTMODE_INT
;
231 if ( ! koptions(&options
, optarg
))
232 return (int)MANDOCLEVEL_BADARG
;
235 search
.argmode
= ARG_EXPR
;
238 search
.argmode
= ARG_FILE
;
239 outmode
= OUTMODE_ALL
;
248 search
.outkey
= optarg
;
249 while (optarg
!= NULL
)
250 manconf_output(&conf
.output
,
251 strsep(&optarg
, ","));
254 search
.arch
= optarg
;
260 if ( ! toptions(&curp
, optarg
))
261 return (int)MANDOCLEVEL_BADARG
;
264 if ( ! woptions(&curp
, optarg
))
265 return (int)MANDOCLEVEL_BADARG
;
268 outmode
= OUTMODE_FLN
;
277 usage(search
.argmode
);
279 /* Postprocess options. */
281 if (outmode
== OUTMODE_DEF
) {
282 switch (search
.argmode
) {
284 outmode
= OUTMODE_ALL
;
288 outmode
= OUTMODE_ONE
;
291 outmode
= OUTMODE_LST
;
296 if (outmode
== OUTMODE_FLN
||
297 outmode
== OUTMODE_LST
||
298 !isatty(STDOUT_FILENO
))
303 if (pledge("stdio rpath flock", NULL
) == -1)
304 err((int)MANDOCLEVEL_SYSERR
, "pledge");
307 /* Parse arguments. */
317 * and for a man(1) section argument without -s.
320 if (search
.argmode
== ARG_NAME
) {
321 if (*progname
== 'h') {
326 } else if (argc
> 1 &&
327 ((uc
= (unsigned char *)argv
[0]) != NULL
) &&
328 ((isdigit(uc
[0]) && (uc
[1] == '\0' ||
329 (isalpha(uc
[1]) && uc
[2] == '\0'))) ||
330 (uc
[0] == 'n' && uc
[1] == '\0'))) {
331 search
.sec
= (char *)uc
;
335 if (search
.arch
== NULL
)
336 search
.arch
= getenv("MACHINE");
338 if (search
.arch
== NULL
)
339 search
.arch
= MACHINE
;
345 /* man(1), whatis(1), apropos(1) */
347 if (search
.argmode
!= ARG_FILE
) {
349 usage(search
.argmode
);
351 if (search
.argmode
== ARG_NAME
&&
352 outmode
== OUTMODE_ONE
)
353 search
.firstmatch
= 1;
355 /* Access the mandoc database. */
357 manconf_parse(&conf
, conf_file
, defpaths
, auxpaths
);
360 if ( ! mansearch(&search
, &conf
.manpath
,
361 argc
, argv
, &res
, &sz
))
362 usage(search
.argmode
);
364 if (search
.argmode
!= ARG_NAME
) {
365 fputs("mandoc: database support not compiled in\n",
367 return (int)MANDOCLEVEL_BADARG
;
373 if (search
.argmode
== ARG_NAME
)
374 fs_search(&search
, &conf
.manpath
,
375 argc
, argv
, &res
, &sz
);
377 warnx("nothing appropriate");
381 rc
= MANDOCLEVEL_BADARG
;
386 * For standard man(1) and -a output mode,
387 * prepare for copying filename pointers
388 * into the program parameter array.
391 if (outmode
== OUTMODE_ONE
) {
394 } else if (outmode
== OUTMODE_ALL
)
397 /* Iterate all matching manuals. */
400 for (i
= 0; i
< sz
; i
++) {
401 if (outmode
== OUTMODE_FLN
)
403 else if (outmode
== OUTMODE_LST
)
404 printf("%s - %s\n", res
[i
].names
,
405 res
[i
].output
== NULL
? "" :
407 else if (outmode
== OUTMODE_ONE
) {
408 /* Search for the best section. */
410 sec
+= strcspn(sec
, "123456789");
413 prio
= sec_prios
[sec
[0] - '1'];
416 if (prio
>= best_prio
)
424 * For man(1), -a and -i output mode, fall through
425 * to the main mandoc(1) code iterating files
426 * and running the parsers on each of them.
429 if (outmode
== OUTMODE_FLN
|| outmode
== OUTMODE_LST
)
437 if (pledge("stdio rpath tmppath tty proc exec", NULL
) == -1)
438 err((int)MANDOCLEVEL_SYSERR
, "pledge");
440 if (pledge("stdio rpath", NULL
) == -1)
441 err((int)MANDOCLEVEL_SYSERR
, "pledge");
445 if (search
.argmode
== ARG_FILE
&& ! moptions(&options
, auxpaths
))
446 return (int)MANDOCLEVEL_BADARG
;
449 curp
.mp
= mparse_alloc(options
, curp
.wlevel
, mmsg
, defos
);
452 * Conditionally start up the lookaside buffer before parsing.
454 if (OUTT_MAN
== curp
.outtype
)
455 mparse_keep(curp
.mp
);
459 tag_files
= tag_init();
460 parse(&curp
, STDIN_FILENO
, "<stdin>");
464 fd
= mparse_open(curp
.mp
, resp
!= NULL
? resp
->file
: *argv
);
467 tag_files
= tag_init();
472 parse(&curp
, fd
, *argv
);
473 else if (resp
->form
& FORM_SRC
) {
474 /* For .so only; ignore failure. */
475 chdir(conf
.manpath
.paths
[resp
->ipath
]);
476 parse(&curp
, fd
, resp
->file
);
478 passthrough(resp
->file
, fd
,
479 conf
.output
.synopsisonly
);
481 if (argc
> 1 && curp
.outtype
<= OUTT_UTF8
)
482 ascii_sepline(curp
.outdata
);
483 } else if (rc
< MANDOCLEVEL_ERROR
)
484 rc
= MANDOCLEVEL_ERROR
;
486 if (MANDOCLEVEL_OK
!= rc
&& curp
.wstop
)
494 mparse_reset(curp
.mp
);
497 if (curp
.outdata
!= NULL
) {
498 switch (curp
.outtype
) {
500 html_free(curp
.outdata
);
505 ascii_free(curp
.outdata
);
509 pspdf_free(curp
.outdata
);
515 mparse_free(curp
.mp
);
519 if (search
.argmode
!= ARG_FILE
) {
522 mansearch_free(res
, sz
);
530 * When using a pager, finish writing both temporary files,
531 * fork it, wait for the user to close it, and clean up.
534 if (tag_files
!= NULL
) {
537 man_pgid
= getpgid(0);
538 tag_files
->tcpgid
= man_pgid
== getpid() ?
539 getpgid(getppid()) : man_pgid
;
544 /* Stop here until moved to the foreground. */
546 tc_pgid
= tcgetpgrp(STDIN_FILENO
);
547 if (tc_pgid
!= man_pgid
) {
548 if (tc_pgid
== pager_pid
) {
549 (void)tcsetpgrp(STDIN_FILENO
,
551 if (signum
== SIGTTIN
)
554 tag_files
->tcpgid
= tc_pgid
;
559 /* Once in the foreground, activate the pager. */
562 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
563 kill(pager_pid
, SIGCONT
);
565 pager_pid
= spawn_pager(tag_files
);
567 /* Wait for the pager to stop or exit. */
569 while ((pid
= waitpid(pager_pid
, &status
,
570 WUNTRACED
)) == -1 && errno
== EINTR
)
575 rc
= MANDOCLEVEL_SYSERR
;
578 if (!WIFSTOPPED(status
))
581 signum
= WSTOPSIG(status
);
590 usage(enum argmode argmode
)
595 fputs("usage: mandoc [-acfhkl] [-I os=name] "
596 "[-K encoding] [-mformat] [-O option]\n"
597 "\t [-T output] [-W level] [file ...]\n", stderr
);
600 fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
601 "[-K encoding] [-M path] [-m path]\n"
602 "\t [-O option=value] [-S subsection] [-s section] "
603 "[-T output] [-W level]\n"
604 "\t [section] name ...\n", stderr
);
607 fputs("usage: whatis [-acfhklw] [-C file] "
608 "[-M path] [-m path] [-O outkey] [-S arch]\n"
609 "\t [-s section] name ...\n", stderr
);
612 fputs("usage: apropos [-acfhklw] [-C file] "
613 "[-M path] [-m path] [-O outkey] [-S arch]\n"
614 "\t [-s section] expression ...\n", stderr
);
617 exit((int)MANDOCLEVEL_BADARG
);
621 fs_lookup(const struct manpaths
*paths
, size_t ipath
,
622 const char *sec
, const char *arch
, const char *name
,
623 struct manpage
**res
, size_t *ressz
)
626 struct manpage
*page
;
631 mandoc_asprintf(&file
, "%s/man%s/%s.%s",
632 paths
->paths
[ipath
], sec
, name
, sec
);
633 if (access(file
, R_OK
) != -1)
637 mandoc_asprintf(&file
, "%s/cat%s/%s.0",
638 paths
->paths
[ipath
], sec
, name
);
639 if (access(file
, R_OK
) != -1) {
646 mandoc_asprintf(&file
, "%s/man%s/%s/%s.%s",
647 paths
->paths
[ipath
], sec
, arch
, name
, sec
);
648 if (access(file
, R_OK
) != -1)
653 mandoc_asprintf(&file
, "%s/man%s/%s.[01-9]*",
654 paths
->paths
[ipath
], sec
, name
);
655 globres
= glob(file
, 0, NULL
, &globinfo
);
656 if (globres
!= 0 && globres
!= GLOB_NOMATCH
)
657 warn("%s: glob", file
);
660 file
= mandoc_strdup(*globinfo
.gl_pathv
);
667 warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
668 name
, sec
, BINM_MAKEWHATIS
, paths
->paths
[ipath
]);
670 *res
= mandoc_reallocarray(*res
, ++*ressz
, sizeof(struct manpage
));
671 page
= *res
+ (*ressz
- 1);
676 page
->bits
= NAME_FILE
& NAME_MASK
;
677 page
->sec
= (*sec
>= '1' && *sec
<= '9') ? *sec
- '1' + 1 : 10;
683 fs_search(const struct mansearch
*cfg
, const struct manpaths
*paths
,
684 int argc
, char **argv
, struct manpage
**res
, size_t *ressz
)
686 const char *const sections
[] =
687 {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
688 const size_t nsec
= sizeof(sections
)/sizeof(sections
[0]);
690 size_t ipath
, isec
, lastsz
;
692 assert(cfg
->argmode
== ARG_NAME
);
697 for (ipath
= 0; ipath
< paths
->sz
; ipath
++) {
698 if (cfg
->sec
!= NULL
) {
699 if (fs_lookup(paths
, ipath
, cfg
->sec
,
700 cfg
->arch
, *argv
, res
, ressz
) &&
703 } else for (isec
= 0; isec
< nsec
; isec
++)
704 if (fs_lookup(paths
, ipath
, sections
[isec
],
705 cfg
->arch
, *argv
, res
, ressz
) &&
709 if (*ressz
== lastsz
)
710 warnx("No entry for %s in the manual.", *argv
);
718 parse(struct curparse
*curp
, int fd
, const char *file
)
720 enum mandoclevel rctmp
;
721 struct roff_man
*man
;
723 /* Begin by parsing the file itself. */
728 rctmp
= mparse_readfd(curp
->mp
, fd
, file
);
729 if (fd
!= STDIN_FILENO
)
735 * With -Wstop and warnings or errors of at least the requested
736 * level, do not produce output.
739 if (rctmp
!= MANDOCLEVEL_OK
&& curp
->wstop
)
742 /* If unset, allocate output dev now (if applicable). */
744 if (curp
->outdata
== NULL
) {
745 switch (curp
->outtype
) {
747 curp
->outdata
= html_alloc(curp
->outopts
);
750 curp
->outdata
= utf8_alloc(curp
->outopts
);
753 curp
->outdata
= locale_alloc(curp
->outopts
);
756 curp
->outdata
= ascii_alloc(curp
->outopts
);
759 curp
->outdata
= pdf_alloc(curp
->outopts
);
762 curp
->outdata
= ps_alloc(curp
->outopts
);
769 mparse_result(curp
->mp
, &man
, NULL
);
771 /* Execute the out device, if it exists. */
775 if (man
->macroset
== MACROSET_MDOC
) {
777 switch (curp
->outtype
) {
779 html_mdoc(curp
->outdata
, man
);
782 tree_mdoc(curp
->outdata
, man
);
785 man_mdoc(curp
->outdata
, man
);
792 terminal_mdoc(curp
->outdata
, man
);
798 if (man
->macroset
== MACROSET_MAN
) {
800 switch (curp
->outtype
) {
802 html_man(curp
->outdata
, man
);
805 tree_man(curp
->outdata
, man
);
808 man_man(curp
->outdata
, man
);
815 terminal_man(curp
->outdata
, man
);
824 passthrough(const char *file
, int fd
, int synopsis_only
)
826 const char synb
[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
827 const char synr
[] = "SYNOPSIS";
838 if ((stream
= fdopen(fd
, "r")) == NULL
) {
845 while (getline(&line
, &linesz
, stream
) != -1) {
849 if ( ! isspace((unsigned char)*cp
))
851 while (isspace((unsigned char)*cp
))
854 if (strcmp(cp
, synb
) == 0 ||
855 strcmp(cp
, synr
) == 0)
860 if (fputs(cp
, stdout
)) {
867 if (ferror(stream
)) {
880 warn("%s: SYSERR: %s", file
, syscall
);
881 if (rc
< MANDOCLEVEL_SYSERR
)
882 rc
= MANDOCLEVEL_SYSERR
;
886 koptions(int *options
, char *arg
)
889 if ( ! strcmp(arg
, "utf-8")) {
890 *options
|= MPARSE_UTF8
;
891 *options
&= ~MPARSE_LATIN1
;
892 } else if ( ! strcmp(arg
, "iso-8859-1")) {
893 *options
|= MPARSE_LATIN1
;
894 *options
&= ~MPARSE_UTF8
;
895 } else if ( ! strcmp(arg
, "us-ascii")) {
896 *options
&= ~(MPARSE_UTF8
| MPARSE_LATIN1
);
898 warnx("-K %s: Bad argument", arg
);
905 moptions(int *options
, char *arg
)
910 else if (0 == strcmp(arg
, "doc"))
911 *options
|= MPARSE_MDOC
;
912 else if (0 == strcmp(arg
, "andoc"))
914 else if (0 == strcmp(arg
, "an"))
915 *options
|= MPARSE_MAN
;
917 warnx("-m %s: Bad argument", arg
);
925 toptions(struct curparse
*curp
, char *arg
)
928 if (0 == strcmp(arg
, "ascii"))
929 curp
->outtype
= OUTT_ASCII
;
930 else if (0 == strcmp(arg
, "lint")) {
931 curp
->outtype
= OUTT_LINT
;
932 curp
->wlevel
= MANDOCLEVEL_WARNING
;
933 } else if (0 == strcmp(arg
, "tree"))
934 curp
->outtype
= OUTT_TREE
;
935 else if (0 == strcmp(arg
, "man"))
936 curp
->outtype
= OUTT_MAN
;
937 else if (0 == strcmp(arg
, "html"))
938 curp
->outtype
= OUTT_HTML
;
939 else if (0 == strcmp(arg
, "utf8"))
940 curp
->outtype
= OUTT_UTF8
;
941 else if (0 == strcmp(arg
, "locale"))
942 curp
->outtype
= OUTT_LOCALE
;
943 else if (0 == strcmp(arg
, "xhtml"))
944 curp
->outtype
= OUTT_HTML
;
945 else if (0 == strcmp(arg
, "ps"))
946 curp
->outtype
= OUTT_PS
;
947 else if (0 == strcmp(arg
, "pdf"))
948 curp
->outtype
= OUTT_PDF
;
950 warnx("-T %s: Bad argument", arg
);
958 woptions(struct curparse
*curp
, char *arg
)
973 switch (getsubopt(&arg
, UNCONST(toks
), &v
)) {
979 curp
->wlevel
= MANDOCLEVEL_WARNING
;
982 curp
->wlevel
= MANDOCLEVEL_ERROR
;
985 curp
->wlevel
= MANDOCLEVEL_UNSUPP
;
988 curp
->wlevel
= MANDOCLEVEL_BADARG
;
991 warnx("-W %s: Bad argument", o
);
1000 mmsg(enum mandocerr t
, enum mandoclevel lvl
,
1001 const char *file
, int line
, int col
, const char *msg
)
1003 const char *mparse_msg
;
1005 fprintf(stderr
, "%s: %s:", getprogname(), file
);
1008 fprintf(stderr
, "%d:%d:", line
, col
+ 1);
1010 fprintf(stderr
, " %s", mparse_strlevel(lvl
));
1012 if (NULL
!= (mparse_msg
= mparse_strerror(t
)))
1013 fprintf(stderr
, ": %s", mparse_msg
);
1016 fprintf(stderr
, ": %s", msg
);
1018 fputc('\n', stderr
);
1022 spawn_pager(struct tag_files
*tag_files
)
1024 const struct timespec timeout
= { 0, 100000000 }; /* 0.1s */
1025 #define MAX_PAGER_ARGS 16
1026 char *argv
[MAX_PAGER_ARGS
];
1033 pager
= getenv("MANPAGER");
1034 if (pager
== NULL
|| *pager
== '\0')
1035 pager
= getenv("PAGER");
1036 if (pager
== NULL
|| *pager
== '\0')
1038 cp
= mandoc_strdup(pager
);
1041 * Parse the pager command into words.
1042 * Intentionally do not do anything fancy here.
1046 while (argc
+ 4 < MAX_PAGER_ARGS
) {
1048 cp
= strchr(cp
, ' ');
1058 /* For more(1) and less(1), use the tag file. */
1060 if ((cmdlen
= strlen(argv
[0])) >= 4) {
1061 cp
= argv
[0] + cmdlen
- 4;
1062 if (strcmp(cp
, "less") == 0 || strcmp(cp
, "more") == 0) {
1063 argv
[argc
++] = mandoc_strdup("-T");
1064 argv
[argc
++] = tag_files
->tfn
;
1067 argv
[argc
++] = tag_files
->ofn
;
1070 switch (pager_pid
= fork()) {
1072 err((int)MANDOCLEVEL_SYSERR
, "fork");
1076 (void)setpgid(pager_pid
, 0);
1077 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
1079 if (pledge("stdio rpath tmppath tty proc", NULL
) == -1)
1080 err((int)MANDOCLEVEL_SYSERR
, "pledge");
1082 tag_files
->pager_pid
= pager_pid
;
1086 /* The child process becomes the pager. */
1088 if (dup2(tag_files
->ofd
, STDOUT_FILENO
) == -1)
1089 err((int)MANDOCLEVEL_SYSERR
, "pager stdout");
1090 close(tag_files
->ofd
);
1091 close(tag_files
->tfd
);
1093 /* Do not start the pager before controlling the terminal. */
1095 while (tcgetpgrp(STDIN_FILENO
) != getpid())
1096 nanosleep(&timeout
, NULL
);
1098 execvp(argv
[0], argv
);
1099 err((int)MANDOCLEVEL_SYSERR
, "exec %s", argv
[0]);