From nate@cs.hmc.edu  Wed Aug  2 00:08:41 2006
Return-Path: <nate@cs.hmc.edu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 34B6916A4E5
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  2 Aug 2006 00:08:41 +0000 (UTC)
	(envelope-from nate@cs.hmc.edu)
Received: from turing.cs.hmc.edu (turing.cs.hmc.edu [134.173.42.99])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D6BE943D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  2 Aug 2006 00:08:40 +0000 (GMT)
	(envelope-from nate@cs.hmc.edu)
Received: from knuth.cs.hmc.edu (knuth.cs.hmc.edu [134.173.42.100])
	by turing.cs.hmc.edu (Postfix) with ESMTP id 5411253279
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  1 Aug 2006 17:08:40 -0700 (PDT)
Received: by knuth.cs.hmc.edu (Postfix, from userid 26983)
	id 45A09BF44; Tue,  1 Aug 2006 17:08:40 -0700 (PDT)
Message-Id: <20060802000840.45A09BF44@knuth.cs.hmc.edu>
Date: Tue,  1 Aug 2006 17:08:40 -0700 (PDT)
From: Nate Eldredge <nge@cs.hmc.edu>
Reply-To: Nate Eldredge <nge@cs.hmc.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: make(1) hangs with -j and -f - (patch)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         101232
>Category:       bin
>Synopsis:       [patch] make(1) hangs with -j and -f
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 02 00:10:13 GMT 2006
>Closed-Date:    Sat Apr 14 05:08:03 GMT 2007
>Last-Modified:  Sat Apr 14 05:08:03 GMT 2007
>Originator:     Nate Eldredge
>Release:        FreeBSD 6.1-RELEASE-p1 amd64
>Organization:
>Environment:
System: FreeBSD vulcan.lan 6.1-RELEASE-p1 FreeBSD 6.1-RELEASE-p1 #1: Wed May 31 21:52:41 PDT 2006 nate@vulcan.lan:/usr/obj/usr/src/sys/VULCAN amd64


	
>Description:

If you run make(1) with -j NN and reading the makefile from standard
input, it hangs.

>How-To-Repeat:


$ cat >mf
all :
	true
^D
$ make -j 6 -f - <mf
(hangs indefinitely)

>Fix:

There is a typo in job.c.  Here is a patch, explanation follows.

--- /usr/src/usr.bin/make/job.c	Wed Jul 20 12:05:23 2005
+++ job.c	Tue Aug  1 16:22:42 2006
@@ -2338,7 +2338,7 @@
 			jobFull = FALSE;
 		}
 	}
-	if (fifoFd <= 0) {
+	if (fifoFd < 0) {
 		maxJobs = maxproc;
 		jobFull = FALSE;
 	} else {

The bug is obvious; this section is supposed to run when the fifo
could not be opened.  But 0 is a valid file descriptor, so fifoFd == 0
does not indicate error.  When -f - is used, make(1) reads its
Makefile from standard input (file descriptor 0) and then closes it.
So now fd 0 is available for reuse.  It winds up getting assigned to
fifoFd.  Now the preceding code clobbers the value of maxproc in the
case that opening the fd succeeded (which is perhaps bad style), so if
this code runs as well, maxJobs gets set to a bogus value (-1) and
things go haywire.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: will 
State-Changed-When: Thu Mar 8 07:57:51 UTC 2007 
State-Changed-Why:  
Fixed in -CURRENT; I may MFC this at a later date. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=101232 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/101232: commit references a PR
Date: Thu,  8 Mar 2007 07:57:51 +0000 (UTC)

 will        2007-03-08 07:57:43 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/make         job.c 
   Log:
   Fix a bug where the standard input (fifoFd == 0) was confused with an
   error return from open(2), leading to an erroneous value of maxJobs and
   a hung make when -f is standard input and -j is used.
   
   PR:             bin/101232
   Submitted by:   Nate Eldredge <nge@cs.hmc.edu>
   
   Revision  Changes    Path
   1.125     +1 -1      src/usr.bin/make/job.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: will 
State-Changed-When: Sat Apr 14 05:05:42 UTC 2007 
State-Changed-Why:  
MFC'd to RELENG_6 as of src/usr.bin/make/job.c:r1.122.2.2. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=101232 
>Unformatted:
