]>
git.cameronkatri.com Git - mandoc.git/blob - main.c
16f55a0923e84fd3d04c38e8a253624bcd3d496d
1 /* $Id: main.c,v 1.273 2016/07/19 13:36:13 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 */
86 int mandocdb(int, char *[]);
89 static int fs_lookup(const struct manpaths
*,
90 size_t ipath
, const char *,
91 const char *, const char *,
92 struct manpage
**, size_t *);
93 static void fs_search(const struct mansearch
*,
94 const struct manpaths
*, int, char**,
95 struct manpage
**, size_t *);
96 static int koptions(int *, char *);
97 static int moptions(int *, char *);
98 static void mmsg(enum mandocerr
, enum mandoclevel
,
99 const char *, int, int, const char *);
100 static void parse(struct curparse
*, int, const char *);
101 static void passthrough(const char *, int, int);
102 static pid_t
spawn_pager(struct tag_files
*);
103 static int toptions(struct curparse
*, char *);
104 static void usage(enum argmode
) __attribute__((noreturn
));
105 static int woptions(struct curparse
*, char *);
107 static const int sec_prios
[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
108 static char help_arg
[] = "help";
109 static char *help_argv
[] = {help_arg
, NULL
};
110 static enum mandoclevel rc
;
114 main(int argc
, char *argv
[])
117 struct curparse curp
;
118 struct mansearch search
;
119 struct tag_files
*tag_files
;
120 const char *progname
;
124 struct manpage
*res
, *resp
;
125 char *conf_file
, *defpaths
;
129 enum outmode outmode
;
136 pid_t pager_pid
, tc_pgid
, man_pgid
, pid
;
139 progname
= getprogname();
142 progname
= mandoc_strdup("mandoc");
143 else if ((progname
= strrchr(argv
[0], '/')) == NULL
)
147 setprogname(progname
);
151 if (strncmp(progname
, "mandocdb", 8) == 0 ||
152 strcmp(progname
, BINM_MAKEWHATIS
) == 0)
153 return mandocdb(argc
, argv
);
157 if (pledge("stdio rpath tmppath tty proc exec flock", NULL
) == -1)
158 err((int)MANDOCLEVEL_SYSERR
, "pledge");
161 #if HAVE_SANDBOX_INIT
162 if (sandbox_init(kSBXProfileNoInternet
, SANDBOX_NAMED
, NULL
) == -1)
163 errx((int)MANDOCLEVEL_SYSERR
, "sandbox_init");
166 /* Search options. */
168 memset(&conf
, 0, sizeof(conf
));
169 conf_file
= defpaths
= NULL
;
172 memset(&search
, 0, sizeof(struct mansearch
));
173 search
.outkey
= "Nd";
175 if (strcmp(progname
, BINM_MAN
) == 0)
176 search
.argmode
= ARG_NAME
;
177 else if (strcmp(progname
, BINM_APROPOS
) == 0)
178 search
.argmode
= ARG_EXPR
;
179 else if (strcmp(progname
, BINM_WHATIS
) == 0)
180 search
.argmode
= ARG_WORD
;
181 else if (strncmp(progname
, "help", 4) == 0)
182 search
.argmode
= ARG_NAME
;
184 search
.argmode
= ARG_FILE
;
186 /* Parser and formatter options. */
188 memset(&curp
, 0, sizeof(struct curparse
));
189 curp
.outtype
= OUTT_LOCALE
;
190 curp
.wlevel
= MANDOCLEVEL_BADARG
;
191 curp
.outopts
= &conf
.output
;
192 options
= MPARSE_SO
| MPARSE_UTF8
| MPARSE_LATIN1
;
198 outmode
= OUTMODE_DEF
;
200 while (-1 != (c
= getopt(argc
, argv
,
201 "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
204 outmode
= OUTMODE_ALL
;
213 search
.argmode
= ARG_WORD
;
216 conf
.output
.synopsisonly
= 1;
218 outmode
= OUTMODE_ALL
;
221 if (strncmp(optarg
, "os=", 3)) {
222 warnx("-I %s: Bad argument", optarg
);
223 return (int)MANDOCLEVEL_BADARG
;
226 warnx("-I %s: Duplicate argument", optarg
);
227 return (int)MANDOCLEVEL_BADARG
;
229 defos
= mandoc_strdup(optarg
+ 3);
232 outmode
= OUTMODE_INT
;
235 if ( ! koptions(&options
, optarg
))
236 return (int)MANDOCLEVEL_BADARG
;
239 search
.argmode
= ARG_EXPR
;
242 search
.argmode
= ARG_FILE
;
243 outmode
= OUTMODE_ALL
;
252 search
.outkey
= optarg
;
253 while (optarg
!= NULL
)
254 manconf_output(&conf
.output
,
255 strsep(&optarg
, ","));
258 search
.arch
= optarg
;
264 if ( ! toptions(&curp
, optarg
))
265 return (int)MANDOCLEVEL_BADARG
;
268 if ( ! woptions(&curp
, optarg
))
269 return (int)MANDOCLEVEL_BADARG
;
272 outmode
= OUTMODE_FLN
;
281 usage(search
.argmode
);
283 /* Postprocess options. */
285 if (outmode
== OUTMODE_DEF
) {
286 switch (search
.argmode
) {
288 outmode
= OUTMODE_ALL
;
292 outmode
= OUTMODE_ONE
;
295 outmode
= OUTMODE_LST
;
300 if (outmode
== OUTMODE_FLN
||
301 outmode
== OUTMODE_LST
||
302 !isatty(STDOUT_FILENO
))
307 if (pledge("stdio rpath flock", NULL
) == -1)
308 err((int)MANDOCLEVEL_SYSERR
, "pledge");
311 /* Parse arguments. */
321 * and for a man(1) section argument without -s.
324 if (search
.argmode
== ARG_NAME
) {
325 if (*progname
== 'h') {
330 } else if (argc
> 1 &&
331 ((uc
= (unsigned char *)argv
[0]) != NULL
) &&
332 ((isdigit(uc
[0]) && (uc
[1] == '\0' ||
333 (isalpha(uc
[1]) && uc
[2] == '\0'))) ||
334 (uc
[0] == 'n' && uc
[1] == '\0'))) {
335 search
.sec
= (char *)uc
;
339 if (search
.arch
== NULL
)
340 search
.arch
= getenv("MACHINE");
342 if (search
.arch
== NULL
)
343 search
.arch
= MACHINE
;
349 /* man(1), whatis(1), apropos(1) */
351 if (search
.argmode
!= ARG_FILE
) {
353 usage(search
.argmode
);
355 if (search
.argmode
== ARG_NAME
&&
356 outmode
== OUTMODE_ONE
)
357 search
.firstmatch
= 1;
359 /* Access the mandoc database. */
361 manconf_parse(&conf
, conf_file
, defpaths
, auxpaths
);
364 if ( ! mansearch(&search
, &conf
.manpath
,
365 argc
, argv
, &res
, &sz
))
366 usage(search
.argmode
);
368 if (search
.argmode
!= ARG_NAME
) {
369 fputs("mandoc: database support not compiled in\n",
371 return (int)MANDOCLEVEL_BADARG
;
377 if (search
.argmode
== ARG_NAME
)
378 fs_search(&search
, &conf
.manpath
,
379 argc
, argv
, &res
, &sz
);
381 warnx("nothing appropriate");
385 rc
= MANDOCLEVEL_BADARG
;
390 * For standard man(1) and -a output mode,
391 * prepare for copying filename pointers
392 * into the program parameter array.
395 if (outmode
== OUTMODE_ONE
) {
398 } else if (outmode
== OUTMODE_ALL
)
401 /* Iterate all matching manuals. */
404 for (i
= 0; i
< sz
; i
++) {
405 if (outmode
== OUTMODE_FLN
)
407 else if (outmode
== OUTMODE_LST
)
408 printf("%s - %s\n", res
[i
].names
,
409 res
[i
].output
== NULL
? "" :
411 else if (outmode
== OUTMODE_ONE
) {
412 /* Search for the best section. */
414 sec
+= strcspn(sec
, "123456789");
417 prio
= sec_prios
[sec
[0] - '1'];
420 if (prio
>= best_prio
)
428 * For man(1), -a and -i output mode, fall through
429 * to the main mandoc(1) code iterating files
430 * and running the parsers on each of them.
433 if (outmode
== OUTMODE_FLN
|| outmode
== OUTMODE_LST
)
441 if (pledge("stdio rpath tmppath tty proc exec", NULL
) == -1)
442 err((int)MANDOCLEVEL_SYSERR
, "pledge");
444 if (pledge("stdio rpath", NULL
) == -1)
445 err((int)MANDOCLEVEL_SYSERR
, "pledge");
449 if (search
.argmode
== ARG_FILE
&& ! moptions(&options
, auxpaths
))
450 return (int)MANDOCLEVEL_BADARG
;
453 curp
.mp
= mparse_alloc(options
, curp
.wlevel
, mmsg
, defos
);
456 * Conditionally start up the lookaside buffer before parsing.
458 if (OUTT_MAN
== curp
.outtype
)
459 mparse_keep(curp
.mp
);
463 tag_files
= tag_init();
464 parse(&curp
, STDIN_FILENO
, "<stdin>");
468 fd
= mparse_open(curp
.mp
, resp
!= NULL
? resp
->file
: *argv
);
471 tag_files
= tag_init();
476 parse(&curp
, fd
, *argv
);
477 else if (resp
->form
& FORM_SRC
) {
478 /* For .so only; ignore failure. */
479 chdir(conf
.manpath
.paths
[resp
->ipath
]);
480 parse(&curp
, fd
, resp
->file
);
482 passthrough(resp
->file
, fd
,
483 conf
.output
.synopsisonly
);
485 if (argc
> 1 && curp
.outtype
<= OUTT_UTF8
)
486 terminal_sepline(curp
.outdata
);
487 } else if (rc
< MANDOCLEVEL_ERROR
)
488 rc
= MANDOCLEVEL_ERROR
;
490 if (MANDOCLEVEL_OK
!= rc
&& curp
.wstop
)
498 mparse_reset(curp
.mp
);
501 if (curp
.outdata
!= NULL
) {
502 switch (curp
.outtype
) {
504 html_free(curp
.outdata
);
509 ascii_free(curp
.outdata
);
513 pspdf_free(curp
.outdata
);
519 mparse_free(curp
.mp
);
523 if (search
.argmode
!= ARG_FILE
) {
526 mansearch_free(res
, sz
);
534 * When using a pager, finish writing both temporary files,
535 * fork it, wait for the user to close it, and clean up.
538 if (tag_files
!= NULL
) {
541 man_pgid
= getpgid(0);
542 tag_files
->tcpgid
= man_pgid
== getpid() ?
543 getpgid(getppid()) : man_pgid
;
548 /* Stop here until moved to the foreground. */
550 tc_pgid
= tcgetpgrp(STDIN_FILENO
);
551 if (tc_pgid
!= man_pgid
) {
552 if (tc_pgid
== pager_pid
) {
553 (void)tcsetpgrp(STDIN_FILENO
,
555 if (signum
== SIGTTIN
)
558 tag_files
->tcpgid
= tc_pgid
;
563 /* Once in the foreground, activate the pager. */
566 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
567 kill(pager_pid
, SIGCONT
);
569 pager_pid
= spawn_pager(tag_files
);
571 /* Wait for the pager to stop or exit. */
573 while ((pid
= waitpid(pager_pid
, &status
,
574 WUNTRACED
)) == -1 && errno
== EINTR
)
579 rc
= MANDOCLEVEL_SYSERR
;
582 if (!WIFSTOPPED(status
))
585 signum
= WSTOPSIG(status
);
594 usage(enum argmode argmode
)
599 fputs("usage: mandoc [-acfhkl] [-I os=name] "
600 "[-K encoding] [-mformat] [-O option]\n"
601 "\t [-T output] [-W level] [file ...]\n", stderr
);
604 fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
605 "[-K encoding] [-M path] [-m path]\n"
606 "\t [-O option=value] [-S subsection] [-s section] "
607 "[-T output] [-W level]\n"
608 "\t [section] name ...\n", stderr
);
611 fputs("usage: whatis [-acfhklw] [-C file] "
612 "[-M path] [-m path] [-O outkey] [-S arch]\n"
613 "\t [-s section] name ...\n", stderr
);
616 fputs("usage: apropos [-acfhklw] [-C file] "
617 "[-M path] [-m path] [-O outkey] [-S arch]\n"
618 "\t [-s section] expression ...\n", stderr
);
621 exit((int)MANDOCLEVEL_BADARG
);
625 fs_lookup(const struct manpaths
*paths
, size_t ipath
,
626 const char *sec
, const char *arch
, const char *name
,
627 struct manpage
**res
, size_t *ressz
)
630 struct manpage
*page
;
635 mandoc_asprintf(&file
, "%s/man%s/%s.%s",
636 paths
->paths
[ipath
], sec
, name
, sec
);
637 if (access(file
, R_OK
) != -1)
641 mandoc_asprintf(&file
, "%s/cat%s/%s.0",
642 paths
->paths
[ipath
], sec
, name
);
643 if (access(file
, R_OK
) != -1) {
650 mandoc_asprintf(&file
, "%s/man%s/%s/%s.%s",
651 paths
->paths
[ipath
], sec
, arch
, name
, sec
);
652 if (access(file
, R_OK
) != -1)
657 mandoc_asprintf(&file
, "%s/man%s/%s.[01-9]*",
658 paths
->paths
[ipath
], sec
, name
);
659 globres
= glob(file
, 0, NULL
, &globinfo
);
660 if (globres
!= 0 && globres
!= GLOB_NOMATCH
)
661 warn("%s: glob", file
);
664 file
= mandoc_strdup(*globinfo
.gl_pathv
);
671 warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
672 name
, sec
, BINM_MAKEWHATIS
, paths
->paths
[ipath
]);
674 *res
= mandoc_reallocarray(*res
, ++*ressz
, sizeof(struct manpage
));
675 page
= *res
+ (*ressz
- 1);
680 page
->bits
= NAME_FILE
& NAME_MASK
;
681 page
->sec
= (*sec
>= '1' && *sec
<= '9') ? *sec
- '1' + 1 : 10;
687 fs_search(const struct mansearch
*cfg
, const struct manpaths
*paths
,
688 int argc
, char **argv
, struct manpage
**res
, size_t *ressz
)
690 const char *const sections
[] =
691 {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
692 const size_t nsec
= sizeof(sections
)/sizeof(sections
[0]);
694 size_t ipath
, isec
, lastsz
;
696 assert(cfg
->argmode
== ARG_NAME
);
701 for (ipath
= 0; ipath
< paths
->sz
; ipath
++) {
702 if (cfg
->sec
!= NULL
) {
703 if (fs_lookup(paths
, ipath
, cfg
->sec
,
704 cfg
->arch
, *argv
, res
, ressz
) &&
707 } else for (isec
= 0; isec
< nsec
; isec
++)
708 if (fs_lookup(paths
, ipath
, sections
[isec
],
709 cfg
->arch
, *argv
, res
, ressz
) &&
713 if (*ressz
== lastsz
)
714 warnx("No entry for %s in the manual.", *argv
);
722 parse(struct curparse
*curp
, int fd
, const char *file
)
724 enum mandoclevel rctmp
;
725 struct roff_man
*man
;
727 /* Begin by parsing the file itself. */
732 rctmp
= mparse_readfd(curp
->mp
, fd
, file
);
733 if (fd
!= STDIN_FILENO
)
739 * With -Wstop and warnings or errors of at least the requested
740 * level, do not produce output.
743 if (rctmp
!= MANDOCLEVEL_OK
&& curp
->wstop
)
746 /* If unset, allocate output dev now (if applicable). */
748 if (curp
->outdata
== NULL
) {
749 switch (curp
->outtype
) {
751 curp
->outdata
= html_alloc(curp
->outopts
);
754 curp
->outdata
= utf8_alloc(curp
->outopts
);
757 curp
->outdata
= locale_alloc(curp
->outopts
);
760 curp
->outdata
= ascii_alloc(curp
->outopts
);
763 curp
->outdata
= pdf_alloc(curp
->outopts
);
766 curp
->outdata
= ps_alloc(curp
->outopts
);
773 mparse_result(curp
->mp
, &man
, NULL
);
775 /* Execute the out device, if it exists. */
779 if (man
->macroset
== MACROSET_MDOC
) {
781 switch (curp
->outtype
) {
783 html_mdoc(curp
->outdata
, man
);
786 tree_mdoc(curp
->outdata
, man
);
789 man_mdoc(curp
->outdata
, man
);
796 terminal_mdoc(curp
->outdata
, man
);
802 if (man
->macroset
== MACROSET_MAN
) {
804 switch (curp
->outtype
) {
806 html_man(curp
->outdata
, man
);
809 tree_man(curp
->outdata
, man
);
812 man_man(curp
->outdata
, man
);
819 terminal_man(curp
->outdata
, man
);
828 passthrough(const char *file
, int fd
, int synopsis_only
)
830 const char synb
[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
831 const char synr
[] = "SYNOPSIS";
842 if ((stream
= fdopen(fd
, "r")) == NULL
) {
849 while (getline(&line
, &linesz
, stream
) != -1) {
853 if ( ! isspace((unsigned char)*cp
))
855 while (isspace((unsigned char)*cp
))
858 if (strcmp(cp
, synb
) == 0 ||
859 strcmp(cp
, synr
) == 0)
864 if (fputs(cp
, stdout
)) {
871 if (ferror(stream
)) {
884 warn("%s: SYSERR: %s", file
, syscall
);
885 if (rc
< MANDOCLEVEL_SYSERR
)
886 rc
= MANDOCLEVEL_SYSERR
;
890 koptions(int *options
, char *arg
)
893 if ( ! strcmp(arg
, "utf-8")) {
894 *options
|= MPARSE_UTF8
;
895 *options
&= ~MPARSE_LATIN1
;
896 } else if ( ! strcmp(arg
, "iso-8859-1")) {
897 *options
|= MPARSE_LATIN1
;
898 *options
&= ~MPARSE_UTF8
;
899 } else if ( ! strcmp(arg
, "us-ascii")) {
900 *options
&= ~(MPARSE_UTF8
| MPARSE_LATIN1
);
902 warnx("-K %s: Bad argument", arg
);
909 moptions(int *options
, char *arg
)
914 else if (0 == strcmp(arg
, "doc"))
915 *options
|= MPARSE_MDOC
;
916 else if (0 == strcmp(arg
, "andoc"))
918 else if (0 == strcmp(arg
, "an"))
919 *options
|= MPARSE_MAN
;
921 warnx("-m %s: Bad argument", arg
);
929 toptions(struct curparse
*curp
, char *arg
)
932 if (0 == strcmp(arg
, "ascii"))
933 curp
->outtype
= OUTT_ASCII
;
934 else if (0 == strcmp(arg
, "lint")) {
935 curp
->outtype
= OUTT_LINT
;
936 curp
->wlevel
= MANDOCLEVEL_WARNING
;
937 } else if (0 == strcmp(arg
, "tree"))
938 curp
->outtype
= OUTT_TREE
;
939 else if (0 == strcmp(arg
, "man"))
940 curp
->outtype
= OUTT_MAN
;
941 else if (0 == strcmp(arg
, "html"))
942 curp
->outtype
= OUTT_HTML
;
943 else if (0 == strcmp(arg
, "utf8"))
944 curp
->outtype
= OUTT_UTF8
;
945 else if (0 == strcmp(arg
, "locale"))
946 curp
->outtype
= OUTT_LOCALE
;
947 else if (0 == strcmp(arg
, "xhtml"))
948 curp
->outtype
= OUTT_HTML
;
949 else if (0 == strcmp(arg
, "ps"))
950 curp
->outtype
= OUTT_PS
;
951 else if (0 == strcmp(arg
, "pdf"))
952 curp
->outtype
= OUTT_PDF
;
954 warnx("-T %s: Bad argument", arg
);
962 woptions(struct curparse
*curp
, char *arg
)
977 switch (getsubopt(&arg
, (char * const *)toks
, &v
)) {
983 curp
->wlevel
= MANDOCLEVEL_WARNING
;
986 curp
->wlevel
= MANDOCLEVEL_ERROR
;
989 curp
->wlevel
= MANDOCLEVEL_UNSUPP
;
992 curp
->wlevel
= MANDOCLEVEL_BADARG
;
995 warnx("-W %s: Bad argument", o
);
1004 mmsg(enum mandocerr t
, enum mandoclevel lvl
,
1005 const char *file
, int line
, int col
, const char *msg
)
1007 const char *mparse_msg
;
1009 fprintf(stderr
, "%s: %s:", getprogname(), file
);
1012 fprintf(stderr
, "%d:%d:", line
, col
+ 1);
1014 fprintf(stderr
, " %s", mparse_strlevel(lvl
));
1016 if (NULL
!= (mparse_msg
= mparse_strerror(t
)))
1017 fprintf(stderr
, ": %s", mparse_msg
);
1020 fprintf(stderr
, ": %s", msg
);
1022 fputc('\n', stderr
);
1026 spawn_pager(struct tag_files
*tag_files
)
1028 const struct timespec timeout
= { 0, 100000000 }; /* 0.1s */
1029 #define MAX_PAGER_ARGS 16
1030 char *argv
[MAX_PAGER_ARGS
];
1037 pager
= getenv("MANPAGER");
1038 if (pager
== NULL
|| *pager
== '\0')
1039 pager
= getenv("PAGER");
1040 if (pager
== NULL
|| *pager
== '\0')
1042 cp
= mandoc_strdup(pager
);
1045 * Parse the pager command into words.
1046 * Intentionally do not do anything fancy here.
1050 while (argc
+ 4 < MAX_PAGER_ARGS
) {
1052 cp
= strchr(cp
, ' ');
1062 /* For less(1), use the tag file. */
1064 if ((cmdlen
= strlen(argv
[0])) >= 4) {
1065 cp
= argv
[0] + cmdlen
- 4;
1066 if (strcmp(cp
, "less") == 0) {
1067 argv
[argc
++] = mandoc_strdup("-T");
1068 argv
[argc
++] = tag_files
->tfn
;
1071 argv
[argc
++] = tag_files
->ofn
;
1074 switch (pager_pid
= fork()) {
1076 err((int)MANDOCLEVEL_SYSERR
, "fork");
1080 (void)setpgid(pager_pid
, 0);
1081 (void)tcsetpgrp(STDIN_FILENO
, pager_pid
);
1083 if (pledge("stdio rpath tmppath tty proc", NULL
) == -1)
1084 err((int)MANDOCLEVEL_SYSERR
, "pledge");
1086 tag_files
->pager_pid
= pager_pid
;
1090 /* The child process becomes the pager. */
1092 if (dup2(tag_files
->ofd
, STDOUT_FILENO
) == -1)
1093 err((int)MANDOCLEVEL_SYSERR
, "pager stdout");
1094 close(tag_files
->ofd
);
1095 close(tag_files
->tfd
);
1097 /* Do not start the pager before controlling the terminal. */
1099 while (tcgetpgrp(STDIN_FILENO
) != getpid())
1100 nanosleep(&timeout
, NULL
);
1102 execvp(argv
[0], argv
);
1103 err((int)MANDOCLEVEL_SYSERR
, "exec %s", argv
[0]);