[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/main.c between version 1.258 and 1.261

version 1.258, 2015/11/14 23:57:47 version 1.261, 2016/01/08 02:13:39
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))
Line 530  out:
Line 535  out:
         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;
Line 542  out:
Line 579  out:
                         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 696  parse(struct curparse *curp, int fd, const char *file)
Line 724  parse(struct curparse *curp, int fd, const char *file)
         /* Begin by parsing the file itself. */          /* Begin by parsing the file itself. */
   
         assert(file);          assert(file);
         assert(fd >= -1);          assert(fd > 0);
   
         rctmp = mparse_readfd(curp->mp, fd, file);          rctmp = mparse_readfd(curp->mp, fd, file);
           if (fd != STDIN_FILENO)
                   close(fd);
         if (rc < rctmp)          if (rc < rctmp)
                 rc = rctmp;                  rc = rctmp;
   
Line 1046  spawn_pager(struct tag_files *tag_files)
Line 1076  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;
         }          }
   

Legend:
Removed from v.1.258  
changed lines
  Added in v.1.261

CVSweb