usr.bin/make/job.c
/*-
 *-----------------------------------------------------------------------
 * Job_CatchOutput --
 *	Catch the output from our children, if we're using
 *	pipes do so. Otherwise just block time until we get a
 *	signal (most likely a SIGCHLD) since there's no point in
 *	just spinning when there's nothing to do and the reaping
 *	of a child can wait for a while. 
 *
 * Results:
 *	None 
 *
 * Side Effects:
 *	Output is read from pipes if we're piping.
 * -----------------------------------------------------------------------
 */
Job_CatchOutput
Catch the output from our children, if we're using
pipes do so. Otherwise just block time until we get a
signal (most likely a SIGCHLD) since there's no point in
just spinning when there's nothing to do and the reaping
of a child can wait for a while.

None

Side Effects:
Output is read from pipes if we're piping.
Job_CatchOutput Catch the output from our children if we ' re using pipes do so . Otherwise just block time until we get a signal ( most likely a SIGCHLD ) since there ' s no point in just spinning when there ' s nothing to do and the reaping of a child can wait for a while . None Side Effects : Output is read from pipes if we ' re piping .
void
Job_CatchOutput ()
{
    int           	  nfds;
    struct timeval	  timeout;
    fd_set           	  readfds;
    register LstNode	  ln;
    register Job   	  *job;
#ifdef RMT_WILL_WATCH
    int	    	  	  pnJobs;   	
#endif
    fflush(stdout);
#ifdef RMT_WILL_WATCH
    pnJobs = nJobs;
    while (nJobs != 0 && pnJobs == nJobs) {
	Rmt_Wait();
    }
#else
    if (usePipes) {
	readfds = outputs;
	timeout.tv_sec = SEL_SEC;
	timeout.tv_usec = SEL_USEC;
	if ((nfds = select (FD_SETSIZE, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout)) < 0)
	{
	    return;
	} else {
	    if (Lst_Open (jobs) == FAILURE) {
		Punt ("Cannot open job table");
	    }
	    while (nfds && (ln = Lst_Next (jobs)) != NILLNODE) {
		job = (Job *) Lst_Datum (ln);
		if (FD_ISSET(job->inPipe, &readfds)) {
		    JobDoOutput (job, FALSE);
		    nfds -= 1;
		}
	    }
	    Lst_Close (jobs);
	}
    }
#endif 
}
void Job_CatchOutput ( ) { int nfds ; struct timeval timeout ; fd_set readfds ; register LstNode ln ; register Job * job ; #ifdef RMT_WILL_WATCH int pnJobs ; #endif fflush ( stdout ) ; #ifdef RMT_WILL_WATCH pnJobs = nJobs ; while ( nJobs != 0 && pnJobs == nJobs ) { Rmt_Wait ( ) ; } #else if ( usePipes ) { readfds = outputs ; timeout . tv_sec = SEL_SEC ; timeout . tv_usec = SEL_USEC ; if ( ( nfds = select ( FD_SETSIZE , & readfds , ( fd_set * ) 0 , ( fd_set * ) 0 , & timeout ) ) < 0 ) { return ; } else { if ( Lst_Open ( jobs ) == FAILURE ) { Punt ( " " ) ; } while ( nfds && ( ln = Lst_Next ( jobs ) ) != NILLNODE ) { job = ( Job * ) Lst_Datum ( ln ) ; if ( FD_ISSET ( job -> inPipe , & readfds ) ) { JobDoOutput ( job , FALSE ) ; nfds -= 1 ; } } Lst_Close ( jobs ) ; } } #endif }
Job_CatchOutput
      Catch the output from our children, if we're using
      pipes do so.
Job_CatchOutput Catch the output from our children if we ' re using pipes do so .
/* Previous nJobs */ /*
     * It is possible for us to be called with nJobs equal to 0. This happens
     * if all the jobs finish and a job that is stopped cannot be run
     * locally (eg if maxLocal is 0) and cannot be exported. The job will
     * be placed back on the stoppedJobs queue, Job_Empty() will return false,
     * Make_Run will call us again when there's nothing for which to wait.
     * nJobs never changes, so we loop forever. Hence the check. It could
     * be argued that we should sleep for a bit so as not to swamp the
     * exportation system with requests. Perhaps we should.
     *
     * NOTE: IT IS THE RESPONSIBILITY OF Rmt_Wait TO CALL Job_CatchChildren
     * IN A TIMELY FASHION TO CATCH ANY LOCALLY RUNNING JOBS THAT EXIT.
     * It may use the variable nLocal to determine if it needs to call
     * Job_CatchChildren (if nLocal is 0, there's nothing for which to
     * wait...)
     */ /* RMT_WILL_WATCH */