]>
git.cameronkatri.com Git - mandoc.git/blob - main.c
1 /* $Id: main.c,v 1.274 2016/07/19 21:31:55 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 */
44 #include "mandoc_aux.h"
52 #include "mansearch.h"
64 OUTT_ASCII
= 0, /* -Tascii */
65 OUTT_LOCALE
, /* -Tlocale */
66 OUTT_UTF8
, /* -Tutf8 */
67 OUTT_TREE
, /* -Ttree */
69 OUTT_HTML
, /* -Thtml */
70 OUTT_LINT
, /* -Tlint */
77 enum mandoclevel wlevel
; /* ignore messages below this */
78 int wstop
; /* stop after a file with a warning */
79 enum outt outtype
; /* which output to use */
80 void *outdata
; /* data for output */
81 struct manoutput
*outopts
; /* output options */
85 int mandocdb(int, char *[]);
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 *);
95 static int moptions(int *, char *);
96 static void mmsg(enum mandocerr
, enum mandoclevel
,
97 const char *, int, int, const char *);
98 static void parse(struct curparse
*, int, const char *);
99 static void passthrough(const char *, int, int);
100 static pid_t
spawn_pager(struct tag_files
*);
101 static int toptions(struct curparse
*, char *);
102 static void usage(enum argmode
) __attribute__((noreturn
));
103 static int woptions(struct curparse
*, char *);
105 static const int sec_prios
[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
106 static char help_arg
[] = "help";
107 static char *help_argv
[] = {help_arg
, NULL
};
108 static enum mandoclevel rc
;
112 main(int argc
, char *argv
[])
115 struct curparse curp
;
116 struct mansearch search
;
117 struct tag_files
*tag_files
;
118 const char *progname
;
122 struct manpage
*res
, *resp
;
123 char *conf_file
, *defpaths
;
127 enum outmode outmode
;
134 pid_t pager_pid
, tc_pgid
, man_pgid
, pid
;
137 progname
= getprogname();
140 progname
= mandoc_strdup("mandoc");
141 else if ((progname
= strrchr(argv
[0], '/')) == NULL
)
145 setprogname(progname
);
148 if (strncmp(progname
, "mandocdb", 8) == 0 ||
149 strcmp(progname
, BINM_MAKEWHATIS
) == 0)
150 return mandocdb(argc
, argv
);
153 if (pledge("stdio rpath tmppath tty proc exec flock", NULL
) == -1)
154 err((int)MANDOCLEVEL_SYSERR
, "pledge");
157 #if HAVE_SANDBOX_INIT
158 if (sandbox_init(kSBXProfileNoInternet
, SANDBOX_NAMED
, NULL
) == -1)
159 errx((int)MANDOCLEVEL_SYSERR
, "sandbox_init");
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
) {
348 if (search
.argmode
== ARG_NAME
&&
349 outmode
== OUTMODE_ONE
)
350 search
.firstmatch
= 1;
352 /* Access the mandoc database. */
354 manconf_parse(&conf
, conf_file
, defpaths
, auxpaths
);
355 if ( ! mansearch(&search
, &conf
.manpath
,
356 argc
, argv
, &res
, &sz
))
357 usage(search
.argmode
);
360 if (search
.argmode
== ARG_NAME
)
361 fs_search(&search
, &conf
.manpath
,
362 argc
, argv
, &res
, &sz
);
364 warnx("nothing appropriate");
368 rc
= MANDOCLEVEL_BADARG
;
373 * For standard man(1) and -a output mode,
374 * prepare for copying filename pointers
375 * into the program parameter array.
378 if (outmode
== OUTMODE_ONE
) {
381 } else if (outmode
== OUTMODE_ALL
)
384 /* Iterate all matching manuals. */
387 for (i
= 0; i
< sz
; i
++) {
388 if (outmode
== OUTMODE_FLN
)
390 else if (outmode
== OUTMODE_LST
)
391 printf("%s - %s\n", res
[i
].names
,
392 res
[i
].output
== NULL
? "" :
394 else if (outmode
== OUTMODE_ONE
) {
395 /* Search for the best section. */
397 sec
+= strcspn(sec
, "123456789");
400 prio
= sec_prios
[sec
[0] - '1'];
403 if (prio
>= best_prio
)
411 * For man(1), -a and -i output mode, fall through
412 * to the main mandoc(1) code iterating files
413 * and running the parsers on each of them.
416 if (outmode
== OUTMODE_FLN
|| outmode
== OUTMODE_LST
)
424 if (pledge("stdio rpath tmppath tty proc exec", NULL
) == -1)
425 err((int)MANDOCLEVEL_SYSERR
, "pledge");
427 if (pledge("stdio rpath", NULL
) == -1)
428 err((int)MANDOCLEVEL_SYSERR
, "pledge");
432 if (search
.argmode
== ARG_FILE
&& ! moptions(&options
, auxpaths
))
433 return (int)MANDOCLEVEL_BADARG
;
436 curp
.mp
= mparse_alloc(options
, curp
.wlevel
, mmsg
, defos
);
439 * Conditionally start up the lookaside buffer before parsing.
441 if (OUTT_MAN
== curp
.outtype
)
442 mparse_keep(curp
.mp
);
446 tag_files
= tag_init();
447 parse(&curp
, STDIN_FILENO
, "<stdin>");
451 fd
= mparse_open(curp
.mp
, resp
!= NULL
? resp
->file
: *argv
);
454 tag_files
= tag_init();
459 parse(&curp
, fd
, *argv
);
460 else if (resp
->form
== FORM_SRC
) {
461 /* For .so only; ignore failure. */
462 chdir(conf
.manpath
.paths
[resp
->ipath
]);
463 parse(&curp
, fd
, resp
->file
);
465 passthrough(resp
->file
, fd
,
466 conf
.output
.synopsisonly
);
468 if (argc
> 1 && curp
.outtype
<= OUTT_UTF8
)
469 terminal_sepline(curp
.outdata
);
470 } else if (rc
< MANDOCLEVEL_ERROR
)
471 rc
= MANDOCLEVEL_ERROR
;
473 if (MANDOCLEVEL_OK
!= rc
&& curp
.wstop
)
481 mparse_reset(curp
.mp
);
484 if (curp
.outdata
!= NULL
) {
485 switch (curp
.outtype
) {
487 html_free(curp
.outdata
);
492 ascii_free(curp
.outdata
);
496 pspdf_free(curp
.outdata
);
502 mparse_free(curp
.mp
);
506 if (search
.argmode
!= ARG_FILE
) {
508 mansearch_free(res
, sz
);
514 * When using a pager, finish writing both temporary files,
515 * fork it, wait for the user to close it, and clean up.
518 if (tag_files
!= NULL
) {
521 man_pgid
= getpgid(0);
522 tag_files
->tcpgid
= man_pgid
== getpid() ?
523 getpgid(getppid()) : man_pgid
;
528 /* Stop here until moved to the foreground. */
530 tc_pgid
= tcgetpgrp(STDIN_FILENO
);
531 if (tc_pgid
!= man_pgid
) {
532 if (tc_pgid
== pager_pid
) {
533 (void)tcsetpgrp(STDIN_FILENO
,
535 if (signum
== SIGTTIN
)
538 tag_files
->tcpgid
= tc_pgid
;
543 /* Once in the foreground, activate the pager. */
546 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
547 kill(pager_pid
, SIGCONT
);
549 pager_pid
= spawn_pager(tag_files
);
551 /* Wait for the pager to stop or exit. */
553 while ((pid
= waitpid(pager_pid
, &status
,
554 WUNTRACED
)) == -1 && errno
== EINTR
)
559 rc
= MANDOCLEVEL_SYSERR
;
562 if (!WIFSTOPPED(status
))
565 signum
= WSTOPSIG(status
);
574 usage(enum argmode argmode
)
579 fputs("usage: mandoc [-acfhkl] [-I os=name] "
580 "[-K encoding] [-mformat] [-O option]\n"
581 "\t [-T output] [-W level] [file ...]\n", stderr
);
584 fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
585 "[-K encoding] [-M path] [-m path]\n"
586 "\t [-O option=value] [-S subsection] [-s section] "
587 "[-T output] [-W level]\n"
588 "\t [section] name ...\n", stderr
);
591 fputs("usage: whatis [-acfhklw] [-C file] "
592 "[-M path] [-m path] [-O outkey] [-S arch]\n"
593 "\t [-s section] name ...\n", stderr
);
596 fputs("usage: apropos [-acfhklw] [-C file] "
597 "[-M path] [-m path] [-O outkey] [-S arch]\n"
598 "\t [-s section] expression ...\n", stderr
);
601 exit((int)MANDOCLEVEL_BADARG
);
605 fs_lookup(const struct manpaths
*paths
, size_t ipath
,
606 const char *sec
, const char *arch
, const char *name
,
607 struct manpage
**res
, size_t *ressz
)
610 struct manpage
*page
;
616 mandoc_asprintf(&file
, "%s/man%s/%s.%s",
617 paths
->paths
[ipath
], sec
, name
, sec
);
618 if (access(file
, R_OK
) != -1)
622 mandoc_asprintf(&file
, "%s/cat%s/%s.0",
623 paths
->paths
[ipath
], sec
, name
);
624 if (access(file
, R_OK
) != -1) {
631 mandoc_asprintf(&file
, "%s/man%s/%s/%s.%s",
632 paths
->paths
[ipath
], sec
, arch
, name
, sec
);
633 if (access(file
, R_OK
) != -1)
638 mandoc_asprintf(&file
, "%s/man%s/%s.[01-9]*",
639 paths
->paths
[ipath
], sec
, name
);
640 globres
= glob(file
, 0, NULL
, &globinfo
);
641 if (globres
!= 0 && globres
!= GLOB_NOMATCH
)
642 warn("%s: glob", file
);
645 file
= mandoc_strdup(*globinfo
.gl_pathv
);
651 warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
652 name
, sec
, BINM_MAKEWHATIS
, paths
->paths
[ipath
]);
653 *res
= mandoc_reallocarray(*res
, ++*ressz
, sizeof(struct manpage
));
654 page
= *res
+ (*ressz
- 1);
659 page
->bits
= NAME_FILE
& NAME_MASK
;
660 page
->sec
= (*sec
>= '1' && *sec
<= '9') ? *sec
- '1' + 1 : 10;
666 fs_search(const struct mansearch
*cfg
, const struct manpaths
*paths
,
667 int argc
, char **argv
, struct manpage
**res
, size_t *ressz
)
669 const char *const sections
[] =
670 {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
671 const size_t nsec
= sizeof(sections
)/sizeof(sections
[0]);
673 size_t ipath
, isec
, lastsz
;
675 assert(cfg
->argmode
== ARG_NAME
);
680 for (ipath
= 0; ipath
< paths
->sz
; ipath
++) {
681 if (cfg
->sec
!= NULL
) {
682 if (fs_lookup(paths
, ipath
, cfg
->sec
,
683 cfg
->arch
, *argv
, res
, ressz
) &&
686 } else for (isec
= 0; isec
< nsec
; isec
++)
687 if (fs_lookup(paths
, ipath
, sections
[isec
],
688 cfg
->arch
, *argv
, res
, ressz
) &&
692 if (*ressz
== lastsz
)
693 warnx("No entry for %s in the manual.", *argv
);
701 parse(struct curparse
*curp
, int fd
, const char *file
)
703 enum mandoclevel rctmp
;
704 struct roff_man
*man
;
706 /* Begin by parsing the file itself. */
711 rctmp
= mparse_readfd(curp
->mp
, fd
, file
);
712 if (fd
!= STDIN_FILENO
)
718 * With -Wstop and warnings or errors of at least the requested
719 * level, do not produce output.
722 if (rctmp
!= MANDOCLEVEL_OK
&& curp
->wstop
)
725 /* If unset, allocate output dev now (if applicable). */
727 if (curp
->outdata
== NULL
) {
728 switch (curp
->outtype
) {
730 curp
->outdata
= html_alloc(curp
->outopts
);
733 curp
->outdata
= utf8_alloc(curp
->outopts
);
736 curp
->outdata
= locale_alloc(curp
->outopts
);
739 curp
->outdata
= ascii_alloc(curp
->outopts
);
742 curp
->outdata
= pdf_alloc(curp
->outopts
);
745 curp
->outdata
= ps_alloc(curp
->outopts
);
752 mparse_result(curp
->mp
, &man
, NULL
);
754 /* Execute the out device, if it exists. */
758 if (man
->macroset
== MACROSET_MDOC
) {
760 switch (curp
->outtype
) {
762 html_mdoc(curp
->outdata
, man
);
765 tree_mdoc(curp
->outdata
, man
);
768 man_mdoc(curp
->outdata
, man
);
775 terminal_mdoc(curp
->outdata
, man
);
781 if (man
->macroset
== MACROSET_MAN
) {
783 switch (curp
->outtype
) {
785 html_man(curp
->outdata
, man
);
788 tree_man(curp
->outdata
, man
);
791 man_man(curp
->outdata
, man
);
798 terminal_man(curp
->outdata
, man
);
807 passthrough(const char *file
, int fd
, int synopsis_only
)
809 const char synb
[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
810 const char synr
[] = "SYNOPSIS";
821 if ((stream
= fdopen(fd
, "r")) == NULL
) {
828 while (getline(&line
, &linesz
, stream
) != -1) {
832 if ( ! isspace((unsigned char)*cp
))
834 while (isspace((unsigned char)*cp
))
837 if (strcmp(cp
, synb
) == 0 ||
838 strcmp(cp
, synr
) == 0)
843 if (fputs(cp
, stdout
)) {
850 if (ferror(stream
)) {
863 warn("%s: SYSERR: %s", file
, syscall
);
864 if (rc
< MANDOCLEVEL_SYSERR
)
865 rc
= MANDOCLEVEL_SYSERR
;
869 koptions(int *options
, char *arg
)
872 if ( ! strcmp(arg
, "utf-8")) {
873 *options
|= MPARSE_UTF8
;
874 *options
&= ~MPARSE_LATIN1
;
875 } else if ( ! strcmp(arg
, "iso-8859-1")) {
876 *options
|= MPARSE_LATIN1
;
877 *options
&= ~MPARSE_UTF8
;
878 } else if ( ! strcmp(arg
, "us-ascii")) {
879 *options
&= ~(MPARSE_UTF8
| MPARSE_LATIN1
);
881 warnx("-K %s: Bad argument", arg
);
888 moptions(int *options
, char *arg
)
893 else if (0 == strcmp(arg
, "doc"))
894 *options
|= MPARSE_MDOC
;
895 else if (0 == strcmp(arg
, "andoc"))
897 else if (0 == strcmp(arg
, "an"))
898 *options
|= MPARSE_MAN
;
900 warnx("-m %s: Bad argument", arg
);
908 toptions(struct curparse
*curp
, char *arg
)
911 if (0 == strcmp(arg
, "ascii"))
912 curp
->outtype
= OUTT_ASCII
;
913 else if (0 == strcmp(arg
, "lint")) {
914 curp
->outtype
= OUTT_LINT
;
915 curp
->wlevel
= MANDOCLEVEL_WARNING
;
916 } else if (0 == strcmp(arg
, "tree"))
917 curp
->outtype
= OUTT_TREE
;
918 else if (0 == strcmp(arg
, "man"))
919 curp
->outtype
= OUTT_MAN
;
920 else if (0 == strcmp(arg
, "html"))
921 curp
->outtype
= OUTT_HTML
;
922 else if (0 == strcmp(arg
, "utf8"))
923 curp
->outtype
= OUTT_UTF8
;
924 else if (0 == strcmp(arg
, "locale"))
925 curp
->outtype
= OUTT_LOCALE
;
926 else if (0 == strcmp(arg
, "xhtml"))
927 curp
->outtype
= OUTT_HTML
;
928 else if (0 == strcmp(arg
, "ps"))
929 curp
->outtype
= OUTT_PS
;
930 else if (0 == strcmp(arg
, "pdf"))
931 curp
->outtype
= OUTT_PDF
;
933 warnx("-T %s: Bad argument", arg
);
941 woptions(struct curparse
*curp
, char *arg
)
956 switch (getsubopt(&arg
, (char * const *)toks
, &v
)) {
962 curp
->wlevel
= MANDOCLEVEL_WARNING
;
965 curp
->wlevel
= MANDOCLEVEL_ERROR
;
968 curp
->wlevel
= MANDOCLEVEL_UNSUPP
;
971 curp
->wlevel
= MANDOCLEVEL_BADARG
;
974 warnx("-W %s: Bad argument", o
);
983 mmsg(enum mandocerr t
, enum mandoclevel lvl
,
984 const char *file
, int line
, int col
, const char *msg
)
986 const char *mparse_msg
;
988 fprintf(stderr
, "%s: %s:", getprogname(), file
);
991 fprintf(stderr
, "%d:%d:", line
, col
+ 1);
993 fprintf(stderr
, " %s", mparse_strlevel(lvl
));
995 if (NULL
!= (mparse_msg
= mparse_strerror(t
)))
996 fprintf(stderr
, ": %s", mparse_msg
);
999 fprintf(stderr
, ": %s", msg
);
1001 fputc('\n', stderr
);
1005 spawn_pager(struct tag_files
*tag_files
)
1007 const struct timespec timeout
= { 0, 100000000 }; /* 0.1s */
1008 #define MAX_PAGER_ARGS 16
1009 char *argv
[MAX_PAGER_ARGS
];
1016 pager
= getenv("MANPAGER");
1017 if (pager
== NULL
|| *pager
== '\0')
1018 pager
= getenv("PAGER");
1019 if (pager
== NULL
|| *pager
== '\0')
1021 cp
= mandoc_strdup(pager
);
1024 * Parse the pager command into words.
1025 * Intentionally do not do anything fancy here.
1029 while (argc
+ 4 < MAX_PAGER_ARGS
) {
1031 cp
= strchr(cp
, ' ');
1041 /* For less(1), use the tag file. */
1043 if ((cmdlen
= strlen(argv
[0])) >= 4) {
1044 cp
= argv
[0] + cmdlen
- 4;
1045 if (strcmp(cp
, "less") == 0) {
1046 argv
[argc
++] = mandoc_strdup("-T");
1047 argv
[argc
++] = tag_files
->tfn
;
1050 argv
[argc
++] = tag_files
->ofn
;
1053 switch (pager_pid
= fork()) {
1055 err((int)MANDOCLEVEL_SYSERR
, "fork");
1059 (void)setpgid(pager_pid
, 0);
1060 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
1062 if (pledge("stdio rpath tmppath tty proc", NULL
) == -1)
1063 err((int)MANDOCLEVEL_SYSERR
, "pledge");
1065 tag_files
->pager_pid
= pager_pid
;
1069 /* The child process becomes the pager. */
1071 if (dup2(tag_files
->ofd
, STDOUT_FILENO
) == -1)
1072 err((int)MANDOCLEVEL_SYSERR
, "pager stdout");
1073 close(tag_files
->ofd
);
1074 close(tag_files
->tfd
);
1076 /* Do not start the pager before controlling the terminal. */
1078 while (tcgetpgrp(STDIN_FILENO
) != getpid())
1079 nanosleep(&timeout
, NULL
);
1081 execvp(argv
[0], argv
);
1082 err((int)MANDOCLEVEL_SYSERR
, "exec %s", argv
[0]);