version 1.258, 2015/11/14 23:57:47 |
version 1.260, 2015/12/15 17:38:45 |
Line 132 main(int argc, char *argv[]) |
|
Line 132 main(int argc, char *argv[]) |
|
int show_usage; |
int show_usage; |
int options; |
int options; |
int use_pager; |
int use_pager; |
int status; |
int status, signum; |
int c; |
int c; |
pid_t pager_pid; |
pid_t pager_pid, tc_pgid, man_pgid, pid; |
|
|
#if HAVE_PROGNAME |
#if HAVE_PROGNAME |
progname = getprogname(); |
progname = getprogname(); |
Line 299 main(int argc, char *argv[]) |
|
Line 299 main(int argc, char *argv[]) |
|
use_pager = 0; |
use_pager = 0; |
|
|
#if HAVE_PLEDGE |
#if HAVE_PLEDGE |
if (!use_pager && pledge("stdio rpath flock", NULL) == -1) |
if (!use_pager) |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
if (pledge("stdio rpath flock", NULL) == -1) |
|
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
#endif |
#endif |
|
|
/* Parse arguments. */ |
/* Parse arguments. */ |
Line 430 main(int argc, char *argv[]) |
|
Line 431 main(int argc, char *argv[]) |
|
/* mandoc(1) */ |
/* mandoc(1) */ |
|
|
#if HAVE_PLEDGE |
#if HAVE_PLEDGE |
if (pledge(use_pager ? "stdio rpath tmppath tty proc exec" : |
if (use_pager) { |
"stdio rpath", NULL) == -1) |
if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
|
} else { |
|
if (pledge("stdio rpath", NULL) == -1) |
|
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
|
} |
#endif |
#endif |
|
|
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
|
|
if (tag_files != NULL) { |
if (tag_files != NULL) { |
fclose(stdout); |
fclose(stdout); |
tag_write(); |
tag_write(); |
pager_pid = spawn_pager(tag_files); |
man_pgid = getpgid(0); |
|
tag_files->tcpgid = man_pgid == getpid() ? |
|
getpgid(getppid()) : man_pgid; |
|
pager_pid = 0; |
|
signum = SIGSTOP; |
for (;;) { |
for (;;) { |
if (waitpid(pager_pid, &status, WUNTRACED) == -1) { |
|
if (errno == EINTR) |
/* Stop here until moved to the foreground. */ |
continue; |
|
|
tc_pgid = tcgetpgrp(STDIN_FILENO); |
|
if (tc_pgid != man_pgid) { |
|
if (tc_pgid == pager_pid) { |
|
(void)tcsetpgrp(STDIN_FILENO, |
|
man_pgid); |
|
if (signum == SIGTTIN) |
|
continue; |
|
} else |
|
tag_files->tcpgid = tc_pgid; |
|
kill(0, signum); |
|
continue; |
|
} |
|
|
|
/* Once in the foreground, activate the pager. */ |
|
|
|
if (pager_pid) { |
|
(void)tcsetpgrp(STDIN_FILENO, pager_pid); |
|
kill(pager_pid, SIGCONT); |
|
} else |
|
pager_pid = spawn_pager(tag_files); |
|
|
|
/* Wait for the pager to stop or exit. */ |
|
|
|
while ((pid = waitpid(pager_pid, &status, |
|
WUNTRACED)) == -1 && errno == EINTR) |
|
continue; |
|
|
|
if (pid == -1) { |
warn("wait"); |
warn("wait"); |
rc = MANDOCLEVEL_SYSERR; |
rc = MANDOCLEVEL_SYSERR; |
break; |
break; |
|
|
if (!WIFSTOPPED(status)) |
if (!WIFSTOPPED(status)) |
break; |
break; |
|
|
(void)tcsetpgrp(STDIN_FILENO, getpgid(0)); |
signum = WSTOPSIG(status); |
kill(0, WSTOPSIG(status)); |
|
|
|
/* |
|
* I'm now stopped. |
|
* When getting SIGCONT, continue here: |
|
*/ |
|
|
|
(void)tcsetpgrp(STDIN_FILENO, pager_pid); |
|
kill(pager_pid, SIGCONT); |
|
} |
} |
tag_unlink(); |
tag_unlink(); |
} |
} |
Line 1046 spawn_pager(struct tag_files *tag_files) |
|
Line 1074 spawn_pager(struct tag_files *tag_files) |
|
break; |
break; |
default: |
default: |
(void)setpgid(pager_pid, 0); |
(void)setpgid(pager_pid, 0); |
if (tcsetpgrp(STDIN_FILENO, pager_pid) == -1) |
(void)tcsetpgrp(STDIN_FILENO, pager_pid); |
err((int)MANDOCLEVEL_SYSERR, "tcsetpgrp"); |
|
#if HAVE_PLEDGE |
#if HAVE_PLEDGE |
if (pledge("stdio rpath tmppath tty proc", NULL) == -1) |
if (pledge("stdio rpath tmppath tty proc", NULL) == -1) |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
#endif |
#endif |
|
tag_files->pager_pid = pager_pid; |
return pager_pid; |
return pager_pid; |
} |
} |
|
|