]>
git.cameronkatri.com Git - mandoc.git/blob - main.c
1 /* $Id: main.c,v 1.280 2017/01/27 13:47:10 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2012, 2014-2017 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 outdata_alloc(struct curparse
*);
99 static void parse(struct curparse
*, int, const char *);
100 static void passthrough(const char *, int, int);
101 static pid_t
spawn_pager(struct tag_files
*);
102 static int toptions(struct curparse
*, char *);
103 static void usage(enum argmode
) __attribute__((noreturn
));
104 static int woptions(struct curparse
*, char *);
106 static const int sec_prios
[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
107 static char help_arg
[] = "help";
108 static char *help_argv
[] = {help_arg
, NULL
};
109 static enum mandoclevel rc
;
113 main(int argc
, char *argv
[])
116 struct curparse curp
;
117 struct mansearch search
;
118 struct tag_files
*tag_files
;
119 const char *progname
;
123 struct manpage
*res
, *resp
;
124 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
);
150 if (strncmp(progname
, "mandocdb", 8) == 0 ||
151 strcmp(progname
, BINM_MAKEWHATIS
) == 0)
152 return mandocdb(argc
, argv
);
155 if (pledge("stdio rpath tmppath tty proc exec flock", NULL
) == -1)
156 err((int)MANDOCLEVEL_SYSERR
, "pledge");
159 #if HAVE_SANDBOX_INIT
160 if (sandbox_init(kSBXProfileNoInternet
, SANDBOX_NAMED
, NULL
) == -1)
161 errx((int)MANDOCLEVEL_SYSERR
, "sandbox_init");
164 /* Search options. */
166 memset(&conf
, 0, sizeof(conf
));
167 conf_file
= defpaths
= NULL
;
170 memset(&search
, 0, sizeof(struct mansearch
));
171 search
.outkey
= "Nd";
173 if (strcmp(progname
, BINM_MAN
) == 0)
174 search
.argmode
= ARG_NAME
;
175 else if (strcmp(progname
, BINM_APROPOS
) == 0)
176 search
.argmode
= ARG_EXPR
;
177 else if (strcmp(progname
, BINM_WHATIS
) == 0)
178 search
.argmode
= ARG_WORD
;
179 else if (strncmp(progname
, "help", 4) == 0)
180 search
.argmode
= ARG_NAME
;
182 search
.argmode
= ARG_FILE
;
184 /* Parser and formatter options. */
186 memset(&curp
, 0, sizeof(struct curparse
));
187 curp
.outtype
= OUTT_LOCALE
;
188 curp
.wlevel
= MANDOCLEVEL_BADARG
;
189 curp
.outopts
= &conf
.output
;
190 options
= MPARSE_SO
| MPARSE_UTF8
| MPARSE_LATIN1
;
196 outmode
= OUTMODE_DEF
;
198 while (-1 != (c
= getopt(argc
, argv
,
199 "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
202 outmode
= OUTMODE_ALL
;
211 search
.argmode
= ARG_WORD
;
214 conf
.output
.synopsisonly
= 1;
216 outmode
= OUTMODE_ALL
;
219 if (strncmp(optarg
, "os=", 3)) {
220 warnx("-I %s: Bad argument", optarg
);
221 return (int)MANDOCLEVEL_BADARG
;
224 warnx("-I %s: Duplicate argument", optarg
);
225 return (int)MANDOCLEVEL_BADARG
;
227 defos
= mandoc_strdup(optarg
+ 3);
230 outmode
= OUTMODE_INT
;
233 if ( ! koptions(&options
, optarg
))
234 return (int)MANDOCLEVEL_BADARG
;
237 search
.argmode
= ARG_EXPR
;
240 search
.argmode
= ARG_FILE
;
241 outmode
= OUTMODE_ALL
;
250 search
.outkey
= optarg
;
251 while (optarg
!= NULL
) {
253 if (manconf_output(&conf
.output
,
254 strsep(&optarg
, ","), 0) == 0)
256 warnx("-O %s: Bad argument", thisarg
);
257 return (int)MANDOCLEVEL_BADARG
;
261 search
.arch
= optarg
;
267 if ( ! toptions(&curp
, optarg
))
268 return (int)MANDOCLEVEL_BADARG
;
271 if ( ! woptions(&curp
, optarg
))
272 return (int)MANDOCLEVEL_BADARG
;
275 outmode
= OUTMODE_FLN
;
284 usage(search
.argmode
);
286 /* Postprocess options. */
288 if (outmode
== OUTMODE_DEF
) {
289 switch (search
.argmode
) {
291 outmode
= OUTMODE_ALL
;
295 outmode
= OUTMODE_ONE
;
298 outmode
= OUTMODE_LST
;
303 if (outmode
== OUTMODE_FLN
||
304 outmode
== OUTMODE_LST
||
305 !isatty(STDOUT_FILENO
))
310 if (pledge("stdio rpath flock", NULL
) == -1)
311 err((int)MANDOCLEVEL_SYSERR
, "pledge");
314 /* Parse arguments. */
324 * and for a man(1) section argument without -s.
327 if (search
.argmode
== ARG_NAME
) {
328 if (*progname
== 'h') {
333 } else if (argc
> 1 &&
334 ((uc
= (unsigned char *)argv
[0]) != NULL
) &&
335 ((isdigit(uc
[0]) && (uc
[1] == '\0' ||
336 (isalpha(uc
[1]) && uc
[2] == '\0'))) ||
337 (uc
[0] == 'n' && uc
[1] == '\0'))) {
338 search
.sec
= (char *)uc
;
342 if (search
.arch
== NULL
)
343 search
.arch
= getenv("MACHINE");
345 if (search
.arch
== NULL
)
346 search
.arch
= MACHINE
;
352 /* man(1), whatis(1), apropos(1) */
354 if (search
.argmode
!= ARG_FILE
) {
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
);
362 if ( ! mansearch(&search
, &conf
.manpath
,
363 argc
, argv
, &res
, &sz
))
364 usage(search
.argmode
);
367 if (search
.argmode
== ARG_NAME
)
368 fs_search(&search
, &conf
.manpath
,
369 argc
, argv
, &res
, &sz
);
371 warnx("nothing appropriate");
375 rc
= MANDOCLEVEL_BADARG
;
380 * For standard man(1) and -a output mode,
381 * prepare for copying filename pointers
382 * into the program parameter array.
385 if (outmode
== OUTMODE_ONE
) {
388 } else if (outmode
== OUTMODE_ALL
)
391 /* Iterate all matching manuals. */
394 for (i
= 0; i
< sz
; i
++) {
395 if (outmode
== OUTMODE_FLN
)
397 else if (outmode
== OUTMODE_LST
)
398 printf("%s - %s\n", res
[i
].names
,
399 res
[i
].output
== NULL
? "" :
401 else if (outmode
== OUTMODE_ONE
) {
402 /* Search for the best section. */
404 sec
+= strcspn(sec
, "123456789");
407 prio
= sec_prios
[sec
[0] - '1'];
410 if (prio
>= best_prio
)
418 * For man(1), -a and -i output mode, fall through
419 * to the main mandoc(1) code iterating files
420 * and running the parsers on each of them.
423 if (outmode
== OUTMODE_FLN
|| outmode
== OUTMODE_LST
)
431 if (pledge("stdio rpath tmppath tty proc exec", NULL
) == -1)
432 err((int)MANDOCLEVEL_SYSERR
, "pledge");
434 if (pledge("stdio rpath", NULL
) == -1)
435 err((int)MANDOCLEVEL_SYSERR
, "pledge");
439 if (search
.argmode
== ARG_FILE
&& ! moptions(&options
, auxpaths
))
440 return (int)MANDOCLEVEL_BADARG
;
443 curp
.mp
= mparse_alloc(options
, curp
.wlevel
, mmsg
, defos
);
446 * Conditionally start up the lookaside buffer before parsing.
448 if (OUTT_MAN
== curp
.outtype
)
449 mparse_keep(curp
.mp
);
453 tag_files
= tag_init();
454 parse(&curp
, STDIN_FILENO
, "<stdin>");
458 fd
= mparse_open(curp
.mp
, resp
!= NULL
? resp
->file
: *argv
);
461 tag_files
= tag_init();
466 parse(&curp
, fd
, *argv
);
467 else if (resp
->form
== FORM_SRC
) {
468 /* For .so only; ignore failure. */
469 chdir(conf
.manpath
.paths
[resp
->ipath
]);
470 parse(&curp
, fd
, resp
->file
);
472 passthrough(resp
->file
, fd
,
473 conf
.output
.synopsisonly
);
475 if (argc
> 1 && curp
.outtype
<= OUTT_UTF8
) {
476 if (curp
.outdata
== NULL
)
477 outdata_alloc(&curp
);
478 terminal_sepline(curp
.outdata
);
480 } else if (rc
< MANDOCLEVEL_ERROR
)
481 rc
= MANDOCLEVEL_ERROR
;
483 if (MANDOCLEVEL_OK
!= rc
&& curp
.wstop
)
491 mparse_reset(curp
.mp
);
494 if (curp
.outdata
!= NULL
) {
495 switch (curp
.outtype
) {
497 html_free(curp
.outdata
);
502 ascii_free(curp
.outdata
);
506 pspdf_free(curp
.outdata
);
512 mparse_free(curp
.mp
);
516 if (search
.argmode
!= ARG_FILE
) {
518 mansearch_free(res
, sz
);
524 * When using a pager, finish writing both temporary files,
525 * fork it, wait for the user to close it, and clean up.
528 if (tag_files
!= NULL
) {
531 man_pgid
= getpgid(0);
532 tag_files
->tcpgid
= man_pgid
== getpid() ?
533 getpgid(getppid()) : man_pgid
;
538 /* Stop here until moved to the foreground. */
540 tc_pgid
= tcgetpgrp(tag_files
->ofd
);
541 if (tc_pgid
!= man_pgid
) {
542 if (tc_pgid
== pager_pid
) {
543 (void)tcsetpgrp(tag_files
->ofd
,
545 if (signum
== SIGTTIN
)
548 tag_files
->tcpgid
= tc_pgid
;
553 /* Once in the foreground, activate the pager. */
556 (void)tcsetpgrp(tag_files
->ofd
, pager_pid
);
557 kill(pager_pid
, SIGCONT
);
559 pager_pid
= spawn_pager(tag_files
);
561 /* Wait for the pager to stop or exit. */
563 while ((pid
= waitpid(pager_pid
, &status
,
564 WUNTRACED
)) == -1 && errno
== EINTR
)
569 rc
= MANDOCLEVEL_SYSERR
;
572 if (!WIFSTOPPED(status
))
575 signum
= WSTOPSIG(status
);
584 usage(enum argmode argmode
)
589 fputs("usage: mandoc [-acfhkl] [-I os=name] "
590 "[-K encoding] [-mformat] [-O option]\n"
591 "\t [-T output] [-W level] [file ...]\n", stderr
);
594 fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
595 "[-K encoding] [-M path] [-m path]\n"
596 "\t [-O option=value] [-S subsection] [-s section] "
597 "[-T output] [-W level]\n"
598 "\t [section] name ...\n", stderr
);
601 fputs("usage: whatis [-acfhklw] [-C file] "
602 "[-M path] [-m path] [-O outkey] [-S arch]\n"
603 "\t [-s section] name ...\n", stderr
);
606 fputs("usage: apropos [-acfhklw] [-C file] "
607 "[-M path] [-m path] [-O outkey] [-S arch]\n"
608 "\t [-s section] expression ...\n", stderr
);
611 exit((int)MANDOCLEVEL_BADARG
);
615 fs_lookup(const struct manpaths
*paths
, size_t ipath
,
616 const char *sec
, const char *arch
, const char *name
,
617 struct manpage
**res
, size_t *ressz
)
620 struct manpage
*page
;
626 mandoc_asprintf(&file
, "%s/man%s/%s.%s",
627 paths
->paths
[ipath
], sec
, name
, sec
);
628 if (access(file
, R_OK
) != -1)
632 mandoc_asprintf(&file
, "%s/cat%s/%s.0",
633 paths
->paths
[ipath
], sec
, name
);
634 if (access(file
, R_OK
) != -1) {
641 mandoc_asprintf(&file
, "%s/man%s/%s/%s.%s",
642 paths
->paths
[ipath
], sec
, arch
, name
, sec
);
643 if (access(file
, R_OK
) != -1)
648 mandoc_asprintf(&file
, "%s/man%s/%s.[01-9]*",
649 paths
->paths
[ipath
], sec
, name
);
650 globres
= glob(file
, 0, NULL
, &globinfo
);
651 if (globres
!= 0 && globres
!= GLOB_NOMATCH
)
652 warn("%s: glob", file
);
655 file
= mandoc_strdup(*globinfo
.gl_pathv
);
661 warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
662 name
, sec
, BINM_MAKEWHATIS
, paths
->paths
[ipath
]);
663 *res
= mandoc_reallocarray(*res
, ++*ressz
, sizeof(struct manpage
));
664 page
= *res
+ (*ressz
- 1);
669 page
->bits
= NAME_FILE
& NAME_MASK
;
670 page
->sec
= (*sec
>= '1' && *sec
<= '9') ? *sec
- '1' + 1 : 10;
676 fs_search(const struct mansearch
*cfg
, const struct manpaths
*paths
,
677 int argc
, char **argv
, struct manpage
**res
, size_t *ressz
)
679 const char *const sections
[] =
680 {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
681 const size_t nsec
= sizeof(sections
)/sizeof(sections
[0]);
683 size_t ipath
, isec
, lastsz
;
685 assert(cfg
->argmode
== ARG_NAME
);
690 for (ipath
= 0; ipath
< paths
->sz
; ipath
++) {
691 if (cfg
->sec
!= NULL
) {
692 if (fs_lookup(paths
, ipath
, cfg
->sec
,
693 cfg
->arch
, *argv
, res
, ressz
) &&
696 } else for (isec
= 0; isec
< nsec
; isec
++)
697 if (fs_lookup(paths
, ipath
, sections
[isec
],
698 cfg
->arch
, *argv
, res
, ressz
) &&
702 if (*ressz
== lastsz
)
703 warnx("No entry for %s in the manual.", *argv
);
711 parse(struct curparse
*curp
, int fd
, const char *file
)
713 enum mandoclevel rctmp
;
714 struct roff_man
*man
;
716 /* Begin by parsing the file itself. */
721 rctmp
= mparse_readfd(curp
->mp
, fd
, file
);
722 if (fd
!= STDIN_FILENO
)
728 * With -Wstop and warnings or errors of at least the requested
729 * level, do not produce output.
732 if (rctmp
!= MANDOCLEVEL_OK
&& curp
->wstop
)
735 if (curp
->outdata
== NULL
)
738 mparse_result(curp
->mp
, &man
, NULL
);
740 /* Execute the out device, if it exists. */
744 if (man
->macroset
== MACROSET_MDOC
) {
746 switch (curp
->outtype
) {
748 html_mdoc(curp
->outdata
, man
);
751 tree_mdoc(curp
->outdata
, man
);
754 man_mdoc(curp
->outdata
, man
);
761 terminal_mdoc(curp
->outdata
, man
);
767 if (man
->macroset
== MACROSET_MAN
) {
769 switch (curp
->outtype
) {
771 html_man(curp
->outdata
, man
);
774 tree_man(curp
->outdata
, man
);
777 man_man(curp
->outdata
, man
);
784 terminal_man(curp
->outdata
, man
);
790 mparse_updaterc(curp
->mp
, &rc
);
794 outdata_alloc(struct curparse
*curp
)
796 switch (curp
->outtype
) {
798 curp
->outdata
= html_alloc(curp
->outopts
);
801 curp
->outdata
= utf8_alloc(curp
->outopts
);
804 curp
->outdata
= locale_alloc(curp
->outopts
);
807 curp
->outdata
= ascii_alloc(curp
->outopts
);
810 curp
->outdata
= pdf_alloc(curp
->outopts
);
813 curp
->outdata
= ps_alloc(curp
->outopts
);
821 passthrough(const char *file
, int fd
, int synopsis_only
)
823 const char synb
[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
824 const char synr
[] = "SYNOPSIS";
830 ssize_t len
, written
;
836 if (fflush(stdout
) == EOF
) {
841 if ((stream
= fdopen(fd
, "r")) == NULL
) {
848 while ((len
= getline(&line
, &linesz
, stream
)) != -1) {
852 if ( ! isspace((unsigned char)*cp
))
854 while (isspace((unsigned char)*cp
)) {
859 if (strcmp(cp
, synb
) == 0 ||
860 strcmp(cp
, synr
) == 0)
865 for (; len
> 0; len
-= written
) {
866 if ((written
= write(STDOUT_FILENO
, cp
, len
)) != -1)
874 if (ferror(stream
)) {
887 warn("%s: SYSERR: %s", file
, syscall
);
888 if (rc
< MANDOCLEVEL_SYSERR
)
889 rc
= MANDOCLEVEL_SYSERR
;
893 koptions(int *options
, char *arg
)
896 if ( ! strcmp(arg
, "utf-8")) {
897 *options
|= MPARSE_UTF8
;
898 *options
&= ~MPARSE_LATIN1
;
899 } else if ( ! strcmp(arg
, "iso-8859-1")) {
900 *options
|= MPARSE_LATIN1
;
901 *options
&= ~MPARSE_UTF8
;
902 } else if ( ! strcmp(arg
, "us-ascii")) {
903 *options
&= ~(MPARSE_UTF8
| MPARSE_LATIN1
);
905 warnx("-K %s: Bad argument", arg
);
912 moptions(int *options
, char *arg
)
917 else if (0 == strcmp(arg
, "doc"))
918 *options
|= MPARSE_MDOC
;
919 else if (0 == strcmp(arg
, "andoc"))
921 else if (0 == strcmp(arg
, "an"))
922 *options
|= MPARSE_MAN
;
924 warnx("-m %s: Bad argument", arg
);
932 toptions(struct curparse
*curp
, char *arg
)
935 if (0 == strcmp(arg
, "ascii"))
936 curp
->outtype
= OUTT_ASCII
;
937 else if (0 == strcmp(arg
, "lint")) {
938 curp
->outtype
= OUTT_LINT
;
939 curp
->wlevel
= MANDOCLEVEL_WARNING
;
940 } else if (0 == strcmp(arg
, "tree"))
941 curp
->outtype
= OUTT_TREE
;
942 else if (0 == strcmp(arg
, "man"))
943 curp
->outtype
= OUTT_MAN
;
944 else if (0 == strcmp(arg
, "html"))
945 curp
->outtype
= OUTT_HTML
;
946 else if (0 == strcmp(arg
, "utf8"))
947 curp
->outtype
= OUTT_UTF8
;
948 else if (0 == strcmp(arg
, "locale"))
949 curp
->outtype
= OUTT_LOCALE
;
950 else if (0 == strcmp(arg
, "xhtml"))
951 curp
->outtype
= OUTT_HTML
;
952 else if (0 == strcmp(arg
, "ps"))
953 curp
->outtype
= OUTT_PS
;
954 else if (0 == strcmp(arg
, "pdf"))
955 curp
->outtype
= OUTT_PDF
;
957 warnx("-T %s: Bad argument", arg
);
965 woptions(struct curparse
*curp
, char *arg
)
980 switch (getsubopt(&arg
, (char * const *)toks
, &v
)) {
986 curp
->wlevel
= MANDOCLEVEL_WARNING
;
989 curp
->wlevel
= MANDOCLEVEL_ERROR
;
992 curp
->wlevel
= MANDOCLEVEL_UNSUPP
;
995 curp
->wlevel
= MANDOCLEVEL_BADARG
;
998 warnx("-W %s: Bad argument", o
);
1007 mmsg(enum mandocerr t
, enum mandoclevel lvl
,
1008 const char *file
, int line
, int col
, const char *msg
)
1010 const char *mparse_msg
;
1012 fprintf(stderr
, "%s: %s:", getprogname(),
1013 file
== NULL
? "<stdin>" : file
);
1016 fprintf(stderr
, "%d:%d:", line
, col
+ 1);
1018 fprintf(stderr
, " %s", mparse_strlevel(lvl
));
1020 if (NULL
!= (mparse_msg
= mparse_strerror(t
)))
1021 fprintf(stderr
, ": %s", mparse_msg
);
1024 fprintf(stderr
, ": %s", msg
);
1026 fputc('\n', stderr
);
1030 spawn_pager(struct tag_files
*tag_files
)
1032 const struct timespec timeout
= { 0, 100000000 }; /* 0.1s */
1033 #define MAX_PAGER_ARGS 16
1034 char *argv
[MAX_PAGER_ARGS
];
1041 pager
= getenv("MANPAGER");
1042 if (pager
== NULL
|| *pager
== '\0')
1043 pager
= getenv("PAGER");
1044 if (pager
== NULL
|| *pager
== '\0')
1046 cp
= mandoc_strdup(pager
);
1049 * Parse the pager command into words.
1050 * Intentionally do not do anything fancy here.
1054 while (argc
+ 4 < MAX_PAGER_ARGS
) {
1056 cp
= strchr(cp
, ' ');
1066 /* For less(1), use the tag file. */
1068 if ((cmdlen
= strlen(argv
[0])) >= 4) {
1069 cp
= argv
[0] + cmdlen
- 4;
1070 if (strcmp(cp
, "less") == 0) {
1071 argv
[argc
++] = mandoc_strdup("-T");
1072 argv
[argc
++] = tag_files
->tfn
;
1075 argv
[argc
++] = tag_files
->ofn
;
1078 switch (pager_pid
= fork()) {
1080 err((int)MANDOCLEVEL_SYSERR
, "fork");
1084 (void)setpgid(pager_pid
, 0);
1085 (void)tcsetpgrp(tag_files
->ofd
, pager_pid
);
1087 if (pledge("stdio rpath tmppath tty proc", NULL
) == -1)
1088 err((int)MANDOCLEVEL_SYSERR
, "pledge");
1090 tag_files
->pager_pid
= pager_pid
;
1094 /* The child process becomes the pager. */
1096 if (dup2(tag_files
->ofd
, STDOUT_FILENO
) == -1)
1097 err((int)MANDOCLEVEL_SYSERR
, "pager stdout");
1098 close(tag_files
->ofd
);
1099 close(tag_files
->tfd
);
1101 /* Do not start the pager before controlling the terminal. */
1103 while (tcgetpgrp(STDOUT_FILENO
) != getpid())
1104 nanosleep(&timeout
, NULL
);
1106 execvp(argv
[0], argv
);
1107 err((int)MANDOCLEVEL_SYSERR
, "exec %s", argv
[0]);