bin/101232: make(1) hangs with -j and -f - (patch)

Nate Eldredge nge at
Wed Aug 2 00:10:15 UTC 2006

>Number:         101232
>Category:       bin
>Synopsis:       make(1) hangs with -j and -f - (patch)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 02 00:10:13 GMT 2006
>Originator:     Nate Eldredge
>Release:        FreeBSD 6.1-RELEASE-p1 amd64
System: FreeBSD vulcan.lan 6.1-RELEASE-p1 FreeBSD 6.1-RELEASE-p1 #1: Wed May 31 21:52:41 PDT 2006 nate at vulcan.lan:/usr/obj/usr/src/sys/VULCAN amd64


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


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


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.

More information about the freebsd-bugs mailing list