2 /* $Id: main.c,v 1.273.2.3 2017/01/09 02:27:58 schwarze Exp $ */
4 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
6 * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/types.h>
23 #include <sys/param.h> /* MACHINE */
45 #include "mandoc_aux.h"
53 #include "mansearch.h"
65 OUTT_ASCII
= 0, /* -Tascii */
66 OUTT_LOCALE
, /* -Tlocale */
67 OUTT_UTF8
, /* -Tutf8 */
68 OUTT_TREE
, /* -Ttree */
70 OUTT_HTML
, /* -Thtml */
71 OUTT_LINT
, /* -Tlint */
78 enum mandoclevel wlevel
; /* ignore messages below this */
79 int wstop
; /* stop after a file with a warning */
80 enum outt outtype
; /* which output to use */
81 void *outdata
; /* data for output */
82 struct manoutput
*outopts
; /* output options */
87 int mandocdb(int, char *[]);
90 static int fs_lookup(const struct manpaths
*,
91 size_t ipath
, const char *,
92 const char *, const char *,
93 struct manpage
**, size_t *);
94 static void fs_search(const struct mansearch
*,
95 const struct manpaths
*, int, char**,
96 struct manpage
**, size_t *);
97 static int koptions(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 outdata_alloc(struct curparse
*);
102 static void parse(struct curparse
*, int, const char *);
103 static void passthrough(const char *, int, int);
104 static pid_t
spawn_pager(struct tag_files
*);
105 static int toptions(struct curparse
*, char *);
106 static void usage(enum argmode
) __attribute__((noreturn
));
107 static int woptions(struct curparse
*, char *);
109 static const int sec_prios
[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
110 static char help_arg
[] = "help";
111 static char *help_argv
[] = {help_arg
, NULL
};
112 static enum mandoclevel rc
;
116 main(int argc
, char *argv
[])
119 struct curparse curp
;
120 struct mansearch search
;
121 struct tag_files
*tag_files
;
122 const char *progname
;
126 struct manpage
*res
, *resp
;
127 char *conf_file
, *defpaths
;
131 enum outmode outmode
;
138 pid_t pager_pid
, tc_pgid
, man_pgid
, pid
;
141 progname
= getprogname();
144 progname
= mandoc_strdup("mandoc");
145 else if ((progname
= strrchr(argv
[0], '/')) == NULL
)
149 setprogname(progname
);
153 if (strncmp(progname
, "mandocdb", 8) == 0 ||
154 strcmp(progname
, BINM_MAKEWHATIS
) == 0)
155 return mandocdb(argc
, argv
);
159 if (pledge("stdio rpath tmppath tty proc exec flock", NULL
) == -1)
160 err((int)MANDOCLEVEL_SYSERR
, "pledge");
163 #if HAVE_SANDBOX_INIT
164 if (sandbox_init(kSBXProfileNoInternet
, SANDBOX_NAMED
, NULL
) == -1)
165 errx((int)MANDOCLEVEL_SYSERR
, "sandbox_init");
168 /* Search options. */
170 memset(&conf
, 0, sizeof(conf
));
171 conf_file
= defpaths
= NULL
;
174 memset(&search
, 0, sizeof(struct mansearch
));
175 search
.outkey
= "Nd";
177 if (strcmp(progname
, BINM_MAN
) == 0)
178 search
.argmode
= ARG_NAME
;
179 else if (strcmp(progname
, BINM_APROPOS
) == 0)
180 search
.argmode
= ARG_EXPR
;
181 else if (strcmp(progname
, BINM_WHATIS
) == 0)
182 search
.argmode
= ARG_WORD
;
183 else if (strncmp(progname
, "help", 4) == 0)
184 search
.argmode
= ARG_NAME
;
186 search
.argmode
= ARG_FILE
;
188 /* Parser and formatter options. */
190 memset(&curp
, 0, sizeof(struct curparse
));
191 curp
.outtype
= OUTT_LOCALE
;
192 curp
.wlevel
= MANDOCLEVEL_BADARG
;
193 curp
.outopts
= &conf
.output
;
194 options
= MPARSE_SO
| MPARSE_UTF8
| MPARSE_LATIN1
;
200 outmode
= OUTMODE_DEF
;
202 while (-1 != (c
= getopt(argc
, argv
,
203 "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
206 outmode
= OUTMODE_ALL
;
215 search
.argmode
= ARG_WORD
;
218 conf
.output
.synopsisonly
= 1;
220 outmode
= OUTMODE_ALL
;
223 if (strncmp(optarg
, "os=", 3)) {
224 warnx("-I %s: Bad argument", optarg
);
225 return (int)MANDOCLEVEL_BADARG
;
228 warnx("-I %s: Duplicate argument", optarg
);
229 return (int)MANDOCLEVEL_BADARG
;
231 defos
= mandoc_strdup(optarg
+ 3);
234 outmode
= OUTMODE_INT
;
237 if ( ! koptions(&options
, optarg
))
238 return (int)MANDOCLEVEL_BADARG
;
241 search
.argmode
= ARG_EXPR
;
244 search
.argmode
= ARG_FILE
;
245 outmode
= OUTMODE_ALL
;
254 search
.outkey
= optarg
;
255 while (optarg
!= NULL
)
256 manconf_output(&conf
.output
,
257 strsep(&optarg
, ","));
260 search
.arch
= optarg
;
266 if ( ! toptions(&curp
, optarg
))
267 return (int)MANDOCLEVEL_BADARG
;
270 if ( ! woptions(&curp
, optarg
))
271 return (int)MANDOCLEVEL_BADARG
;
274 outmode
= OUTMODE_FLN
;
283 usage(search
.argmode
);
285 /* Postprocess options. */
287 if (outmode
== OUTMODE_DEF
) {
288 switch (search
.argmode
) {
290 outmode
= OUTMODE_ALL
;
294 outmode
= OUTMODE_ONE
;
297 outmode
= OUTMODE_LST
;
302 if (outmode
== OUTMODE_FLN
||
303 outmode
== OUTMODE_LST
||
304 !isatty(STDOUT_FILENO
))
309 if (pledge("stdio rpath flock", NULL
) == -1)
310 err((int)MANDOCLEVEL_SYSERR
, "pledge");
313 /* Parse arguments. */
323 * and for a man(1) section argument without -s.
326 if (search
.argmode
== ARG_NAME
) {
327 if (*progname
== 'h') {
332 } else if (argc
> 1 &&
333 ((uc
= (unsigned char *)argv
[0]) != NULL
) &&
334 ((isdigit(uc
[0]) && (uc
[1] == '\0' ||
335 (isalpha(uc
[1]) && uc
[2] == '\0'))) ||
336 (uc
[0] == 'n' && uc
[1] == '\0'))) {
337 search
.sec
= (char *)uc
;
341 if (search
.arch
== NULL
)
342 search
.arch
= getenv("MACHINE");
344 if (search
.arch
== NULL
)
345 search
.arch
= MACHINE
;
351 /* man(1), whatis(1), apropos(1) */
353 if (search
.argmode
!= ARG_FILE
) {
355 usage(search
.argmode
);
357 if (search
.argmode
== ARG_NAME
&&
358 outmode
== OUTMODE_ONE
)
359 search
.firstmatch
= 1;
361 /* Access the mandoc database. */
363 manconf_parse(&conf
, conf_file
, defpaths
, auxpaths
);
366 if ( ! mansearch(&search
, &conf
.manpath
,
367 argc
, argv
, &res
, &sz
))
368 usage(search
.argmode
);
370 if (search
.argmode
!= ARG_NAME
) {
371 fputs("mandoc: database support not compiled in\n",
373 return (int)MANDOCLEVEL_BADARG
;
379 if (search
.argmode
== ARG_NAME
)
380 fs_search(&search
, &conf
.manpath
,
381 argc
, argv
, &res
, &sz
);
383 warnx("nothing appropriate");
387 rc
= MANDOCLEVEL_BADARG
;
392 * For standard man(1) and -a output mode,
393 * prepare for copying filename pointers
394 * into the program parameter array.
397 if (outmode
== OUTMODE_ONE
) {
400 } else if (outmode
== OUTMODE_ALL
)
403 /* Iterate all matching manuals. */
406 for (i
= 0; i
< sz
; i
++) {
407 if (outmode
== OUTMODE_FLN
)
409 else if (outmode
== OUTMODE_LST
)
410 printf("%s - %s\n", res
[i
].names
,
411 res
[i
].output
== NULL
? "" :
413 else if (outmode
== OUTMODE_ONE
) {
414 /* Search for the best section. */
416 sec
+= strcspn(sec
, "123456789");
419 prio
= sec_prios
[sec
[0] - '1'];
422 if (prio
>= best_prio
)
430 * For man(1), -a and -i output mode, fall through
431 * to the main mandoc(1) code iterating files
432 * and running the parsers on each of them.
435 if (outmode
== OUTMODE_FLN
|| outmode
== OUTMODE_LST
)
443 if (pledge("stdio rpath tmppath tty proc exec", NULL
) == -1)
444 err((int)MANDOCLEVEL_SYSERR
, "pledge");
446 if (pledge("stdio rpath", NULL
) == -1)
447 err((int)MANDOCLEVEL_SYSERR
, "pledge");
451 if (search
.argmode
== ARG_FILE
&& ! moptions(&options
, auxpaths
))
452 return (int)MANDOCLEVEL_BADARG
;
455 curp
.mp
= mparse_alloc(options
, curp
.wlevel
, mmsg
, defos
);
458 * Conditionally start up the lookaside buffer before parsing.
460 if (OUTT_MAN
== curp
.outtype
)
461 mparse_keep(curp
.mp
);
465 tag_files
= tag_init();
466 parse(&curp
, STDIN_FILENO
, "<stdin>");
470 fd
= mparse_open(curp
.mp
, resp
!= NULL
? resp
->file
: *argv
);
473 tag_files
= tag_init();
478 parse(&curp
, fd
, *argv
);
479 else if (resp
->form
& FORM_SRC
) {
480 /* For .so only; ignore failure. */
481 chdir(conf
.manpath
.paths
[resp
->ipath
]);
482 parse(&curp
, fd
, resp
->file
);
484 passthrough(resp
->file
, fd
,
485 conf
.output
.synopsisonly
);
487 if (argc
> 1 && curp
.outtype
<= OUTT_UTF8
) {
488 if (curp
.outdata
== NULL
)
489 outdata_alloc(&curp
);
490 terminal_sepline(curp
.outdata
);
492 } else if (rc
< MANDOCLEVEL_ERROR
)
493 rc
= MANDOCLEVEL_ERROR
;
495 if (MANDOCLEVEL_OK
!= rc
&& curp
.wstop
)
503 mparse_reset(curp
.mp
);
506 if (curp
.outdata
!= NULL
) {
507 switch (curp
.outtype
) {
509 html_free(curp
.outdata
);
514 ascii_free(curp
.outdata
);
518 pspdf_free(curp
.outdata
);
524 mparse_free(curp
.mp
);
528 if (search
.argmode
!= ARG_FILE
) {
531 mansearch_free(res
, sz
);
539 * When using a pager, finish writing both temporary files,
540 * fork it, wait for the user to close it, and clean up.
543 if (tag_files
!= NULL
) {
546 man_pgid
= getpgid(0);
547 tag_files
->tcpgid
= man_pgid
== getpid() ?
548 getpgid(getppid()) : man_pgid
;
553 /* Stop here until moved to the foreground. */
555 tc_pgid
= tcgetpgrp(STDIN_FILENO
);
556 if (tc_pgid
!= man_pgid
) {
557 if (tc_pgid
== pager_pid
) {
558 (void)tcsetpgrp(STDIN_FILENO
,
560 if (signum
== SIGTTIN
)
563 tag_files
->tcpgid
= tc_pgid
;
568 /* Once in the foreground, activate the pager. */
571 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
572 kill(pager_pid
, SIGCONT
);
574 pager_pid
= spawn_pager(tag_files
);
576 /* Wait for the pager to stop or exit. */
578 while ((pid
= waitpid(pager_pid
, &status
,
579 WUNTRACED
)) == -1 && errno
== EINTR
)
584 rc
= MANDOCLEVEL_SYSERR
;
587 if (!WIFSTOPPED(status
))
590 signum
= WSTOPSIG(status
);
599 usage(enum argmode argmode
)
604 fputs("usage: mandoc [-acfhkl] [-I os=name] "
605 "[-K encoding] [-mformat] [-O option]\n"
606 "\t [-T output] [-W level] [file ...]\n", stderr
);
609 fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
610 "[-K encoding] [-M path] [-m path]\n"
611 "\t [-O option=value] [-S subsection] [-s section] "
612 "[-T output] [-W level]\n"
613 "\t [section] name ...\n", stderr
);
616 fputs("usage: whatis [-acfhklw] [-C file] "
617 "[-M path] [-m path] [-O outkey] [-S arch]\n"
618 "\t [-s section] name ...\n", stderr
);
621 fputs("usage: apropos [-acfhklw] [-C file] "
622 "[-M path] [-m path] [-O outkey] [-S arch]\n"
623 "\t [-s section] expression ...\n", stderr
);
626 exit((int)MANDOCLEVEL_BADARG
);
630 fs_lookup(const struct manpaths
*paths
, size_t ipath
,
631 const char *sec
, const char *arch
, const char *name
,
632 struct manpage
**res
, size_t *ressz
)
635 struct manpage
*page
;
640 mandoc_asprintf(&file
, "%s/man%s/%s.%s",
641 paths
->paths
[ipath
], sec
, name
, sec
);
642 if (access(file
, R_OK
) != -1)
646 mandoc_asprintf(&file
, "%s/cat%s/%s.0",
647 paths
->paths
[ipath
], sec
, name
);
648 if (access(file
, R_OK
) != -1) {
655 mandoc_asprintf(&file
, "%s/man%s/%s/%s.%s",
656 paths
->paths
[ipath
], sec
, arch
, name
, sec
);
657 if (access(file
, R_OK
) != -1)
662 mandoc_asprintf(&file
, "%s/man%s/%s.[01-9]*",
663 paths
->paths
[ipath
], sec
, name
);
664 globres
= glob(file
, 0, NULL
, &globinfo
);
665 if (globres
!= 0 && globres
!= GLOB_NOMATCH
)
666 warn("%s: glob", file
);
669 file
= mandoc_strdup(*globinfo
.gl_pathv
);
676 warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
677 name
, sec
, BINM_MAKEWHATIS
, paths
->paths
[ipath
]);
679 *res
= mandoc_reallocarray(*res
, ++*ressz
, sizeof(struct manpage
));
680 page
= *res
+ (*ressz
- 1);
685 page
->bits
= NAME_FILE
& NAME_MASK
;
686 page
->sec
= (*sec
>= '1' && *sec
<= '9') ? *sec
- '1' + 1 : 10;
692 fs_search(const struct mansearch
*cfg
, const struct manpaths
*paths
,
693 int argc
, char **argv
, struct manpage
**res
, size_t *ressz
)
695 const char *const sections
[] =
696 {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
697 const size_t nsec
= sizeof(sections
)/sizeof(sections
[0]);
699 size_t ipath
, isec
, lastsz
;
701 assert(cfg
->argmode
== ARG_NAME
);
706 for (ipath
= 0; ipath
< paths
->sz
; ipath
++) {
707 if (cfg
->sec
!= NULL
) {
708 if (fs_lookup(paths
, ipath
, cfg
->sec
,
709 cfg
->arch
, *argv
, res
, ressz
) &&
712 } else for (isec
= 0; isec
< nsec
; isec
++)
713 if (fs_lookup(paths
, ipath
, sections
[isec
],
714 cfg
->arch
, *argv
, res
, ressz
) &&
718 if (*ressz
== lastsz
)
719 warnx("No entry for %s in the manual.", *argv
);
727 parse(struct curparse
*curp
, int fd
, const char *file
)
729 enum mandoclevel rctmp
;
730 struct roff_man
*man
;
732 /* Begin by parsing the file itself. */
737 rctmp
= mparse_readfd(curp
->mp
, fd
, file
);
738 if (fd
!= STDIN_FILENO
)
744 * With -Wstop and warnings or errors of at least the requested
745 * level, do not produce output.
748 if (rctmp
!= MANDOCLEVEL_OK
&& curp
->wstop
)
751 if (curp
->outdata
== NULL
)
754 mparse_result(curp
->mp
, &man
, NULL
);
756 /* Execute the out device, if it exists. */
760 if (man
->macroset
== MACROSET_MDOC
) {
762 switch (curp
->outtype
) {
764 html_mdoc(curp
->outdata
, man
);
767 tree_mdoc(curp
->outdata
, man
);
770 man_mdoc(curp
->outdata
, man
);
777 terminal_mdoc(curp
->outdata
, man
);
783 if (man
->macroset
== MACROSET_MAN
) {
785 switch (curp
->outtype
) {
787 html_man(curp
->outdata
, man
);
790 tree_man(curp
->outdata
, man
);
793 man_man(curp
->outdata
, man
);
800 terminal_man(curp
->outdata
, man
);
806 mparse_updaterc(curp
->mp
, &rc
);
810 outdata_alloc(struct curparse
*curp
)
812 switch (curp
->outtype
) {
814 curp
->outdata
= html_alloc(curp
->outopts
);
817 curp
->outdata
= utf8_alloc(curp
->outopts
);
820 curp
->outdata
= locale_alloc(curp
->outopts
);
823 curp
->outdata
= ascii_alloc(curp
->outopts
);
826 curp
->outdata
= pdf_alloc(curp
->outopts
);
829 curp
->outdata
= ps_alloc(curp
->outopts
);
837 passthrough(const char *file
, int fd
, int synopsis_only
)
839 const char synb
[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
840 const char synr
[] = "SYNOPSIS";
846 ssize_t len
, written
;
852 if (fflush(stdout
) == EOF
) {
857 if ((stream
= fdopen(fd
, "r")) == NULL
) {
864 while ((len
= getline(&line
, &linesz
, stream
)) != -1) {
868 if ( ! isspace((unsigned char)*cp
))
870 while (isspace((unsigned char)*cp
)) {
875 if (strcmp(cp
, synb
) == 0 ||
876 strcmp(cp
, synr
) == 0)
881 for (; len
> 0; len
-= written
) {
882 if ((written
= write(STDOUT_FILENO
, cp
, len
)) != -1)
890 if (ferror(stream
)) {
903 warn("%s: SYSERR: %s", file
, syscall
);
904 if (rc
< MANDOCLEVEL_SYSERR
)
905 rc
= MANDOCLEVEL_SYSERR
;
909 koptions(int *options
, char *arg
)
912 if ( ! strcmp(arg
, "utf-8")) {
913 *options
|= MPARSE_UTF8
;
914 *options
&= ~MPARSE_LATIN1
;
915 } else if ( ! strcmp(arg
, "iso-8859-1")) {
916 *options
|= MPARSE_LATIN1
;
917 *options
&= ~MPARSE_UTF8
;
918 } else if ( ! strcmp(arg
, "us-ascii")) {
919 *options
&= ~(MPARSE_UTF8
| MPARSE_LATIN1
);
921 warnx("-K %s: Bad argument", arg
);
928 moptions(int *options
, char *arg
)
933 else if (0 == strcmp(arg
, "doc"))
934 *options
|= MPARSE_MDOC
;
935 else if (0 == strcmp(arg
, "andoc"))
937 else if (0 == strcmp(arg
, "an"))
938 *options
|= MPARSE_MAN
;
940 warnx("-m %s: Bad argument", arg
);
948 toptions(struct curparse
*curp
, char *arg
)
951 if (0 == strcmp(arg
, "ascii"))
952 curp
->outtype
= OUTT_ASCII
;
953 else if (0 == strcmp(arg
, "lint")) {
954 curp
->outtype
= OUTT_LINT
;
955 curp
->wlevel
= MANDOCLEVEL_WARNING
;
956 } else if (0 == strcmp(arg
, "tree"))
957 curp
->outtype
= OUTT_TREE
;
958 else if (0 == strcmp(arg
, "man"))
959 curp
->outtype
= OUTT_MAN
;
960 else if (0 == strcmp(arg
, "html"))
961 curp
->outtype
= OUTT_HTML
;
962 else if (0 == strcmp(arg
, "utf8"))
963 curp
->outtype
= OUTT_UTF8
;
964 else if (0 == strcmp(arg
, "locale"))
965 curp
->outtype
= OUTT_LOCALE
;
966 else if (0 == strcmp(arg
, "xhtml"))
967 curp
->outtype
= OUTT_HTML
;
968 else if (0 == strcmp(arg
, "ps"))
969 curp
->outtype
= OUTT_PS
;
970 else if (0 == strcmp(arg
, "pdf"))
971 curp
->outtype
= OUTT_PDF
;
973 warnx("-T %s: Bad argument", arg
);
981 woptions(struct curparse
*curp
, char *arg
)
996 switch (getsubopt(&arg
, (char * const *)toks
, &v
)) {
1002 curp
->wlevel
= MANDOCLEVEL_WARNING
;
1005 curp
->wlevel
= MANDOCLEVEL_ERROR
;
1008 curp
->wlevel
= MANDOCLEVEL_UNSUPP
;
1011 curp
->wlevel
= MANDOCLEVEL_BADARG
;
1014 warnx("-W %s: Bad argument", o
);
1023 mmsg(enum mandocerr t
, enum mandoclevel lvl
,
1024 const char *file
, int line
, int col
, const char *msg
)
1026 const char *mparse_msg
;
1028 fprintf(stderr
, "%s: %s:", getprogname(),
1029 file
== NULL
? "<stdin>" : file
);
1032 fprintf(stderr
, "%d:%d:", line
, col
+ 1);
1034 fprintf(stderr
, " %s", mparse_strlevel(lvl
));
1036 if (NULL
!= (mparse_msg
= mparse_strerror(t
)))
1037 fprintf(stderr
, ": %s", mparse_msg
);
1040 fprintf(stderr
, ": %s", msg
);
1042 fputc('\n', stderr
);
1046 spawn_pager(struct tag_files
*tag_files
)
1048 const struct timespec timeout
= { 0, 100000000 }; /* 0.1s */
1049 #define MAX_PAGER_ARGS 16
1050 char *argv
[MAX_PAGER_ARGS
];
1057 pager
= getenv("MANPAGER");
1058 if (pager
== NULL
|| *pager
== '\0')
1059 pager
= getenv("PAGER");
1060 if (pager
== NULL
|| *pager
== '\0')
1062 cp
= mandoc_strdup(pager
);
1065 * Parse the pager command into words.
1066 * Intentionally do not do anything fancy here.
1070 while (argc
+ 4 < MAX_PAGER_ARGS
) {
1072 cp
= strchr(cp
, ' ');
1082 /* For less(1), use the tag file. */
1084 if ((cmdlen
= strlen(argv
[0])) >= 4) {
1085 cp
= argv
[0] + cmdlen
- 4;
1086 if (strcmp(cp
, "less") == 0) {
1087 argv
[argc
++] = mandoc_strdup("-T");
1088 argv
[argc
++] = tag_files
->tfn
;
1091 argv
[argc
++] = tag_files
->ofn
;
1094 switch (pager_pid
= fork()) {
1096 err((int)MANDOCLEVEL_SYSERR
, "fork");
1100 (void)setpgid(pager_pid
, 0);
1101 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
1103 if (pledge("stdio rpath tmppath tty proc", NULL
) == -1)
1104 err((int)MANDOCLEVEL_SYSERR
, "pledge");
1106 tag_files
->pager_pid
= pager_pid
;
1110 /* The child process becomes the pager. */
1112 if (dup2(tag_files
->ofd
, STDOUT_FILENO
) == -1)
1113 err((int)MANDOCLEVEL_SYSERR
, "pager stdout");
1114 close(tag_files
->ofd
);
1115 close(tag_files
->tfd
);
1117 /* Do not start the pager before controlling the terminal. */
1119 while (tcgetpgrp(STDIN_FILENO
) != getpid())
1120 nanosleep(&timeout
, NULL
);
1122 execvp(argv
[0], argv
);
1123 err((int)MANDOCLEVEL_SYSERR
, "exec %s", argv
[0]);