[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.259

version 1.258, 2015/11/14 23:57:47 version 1.259, 2015/11/20 21:59:54
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 530  out:
Line 530  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 574  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 1046  spawn_pager(struct tag_files *tag_files)
Line 1069  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.259

CVSweb