Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Dec 2011 14:50:26 +0700
From:      Max Khon <fjoe@FreeBSD.org>
To:        Alexander Best <arundel@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r228157 - head/usr.bin/make
Message-ID:  <CADe0-4mJMTuEjY9Bv0r04ET0eb2hHTZ7WvQGobGsg4XJbXfF%2BA@mail.gmail.com>
In-Reply-To: <CADe0-4keJ=DAUGx_FEqpFinyZUC-VdBkquMLW0wDmFHiW9erbw@mail.gmail.com>
References:  <201111301807.pAUI7cXI008371@svn.freebsd.org> <20111201001646.GA49249@freebsd.org> <CADe0-4=izivfmpC_w%2BahNRNrqv%2B3rwRiEbX4wEr8FaBB0q-N5A@mail.gmail.com> <CADe0-4keJ=DAUGx_FEqpFinyZUC-VdBkquMLW0wDmFHiW9erbw@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Alexander,

On Thu, Dec 1, 2011 at 12:03 PM, Max Khon <fjoe@freebsd.org> wrote:

it would also be nice, if at some point, somebody could dive into the code
>>> to
>>> see why 'make buildkernel' will let clang produce coloured output, but
>>> 'make -j(N>1) buildkernel' doesn't (and why adding a -B switch to that
>>> command
>>> fixes it).
>>>
>>
>> This one is simple: job make (-jX) runs commands with stdin/stdout/stderr
>> redirected to pipes.
>> -B turns on compat mode for job make.
>>
>> This can be demonstrated by running make with -jX or -jX -B with the
>> following Makefile:
>> --- cut here ---
>> all:
>>         @if [ -t 1 ]; then echo "stdout is a tty"; else echo "stdout is
>> not a tty"; fi
>> --- cut here ---
>>
>> If you really want to see colored output in -jX case you should teach
>> clang to output ANSI color sequences not only in isatty(1) case, but also
>> when MAKE_JOBS_FIFO environment variable is present (it is set when make
>> runs in job mode).
>>
>
> This will not work for the cases when make(1) is itself redirected.
> Something like attached patch should work, but it blocks sometimes in
> "ttyout" state for some reason (needs more work).
>

It hangs when tty_drain() is called when make(1) closes slave pty. Looks
like a race condition there when tty_wait() is called from tty_drain().

If I exchange pty master and slave hangs disappear. So attached patch works
for me.
It may add performance penalty but I think that the impact will be
negligible.

Max

[-- Attachment #2 --]
Index: usr.bin/make/Makefile
===================================================================
--- usr.bin/make/Makefile	(revision 228157)
+++ usr.bin/make/Makefile	(working copy)
@@ -7,6 +7,8 @@
 SRCS=	arch.c buf.c cond.c dir.c for.c hash.c hash_tables.c job.c	\
 	lst.c main.c make.c parse.c proc.c shell.c str.c suff.c targ.c	\
 	util.c var.c
+DPADD=	${LIBUTIL}
+LDADD=	-lutil
 
 NO_SHARED?=	YES
 
Index: usr.bin/make/job.c
===================================================================
--- usr.bin/make/job.c	(revision 228157)
+++ usr.bin/make/job.c	(working copy)
@@ -115,6 +115,7 @@
 #include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <libutil.h>
 #include <paths.h>
 #include <string.h>
 #include <signal.h>
@@ -1798,8 +1799,13 @@
 		if (usePipes) {
 			int fd[2];
 
-			if (pipe(fd) == -1)
-				Punt("Cannot create pipe: %s", strerror(errno));
+			if (isatty(1)) {
+				if (openpty(fd + 1, fd + 0, NULL, NULL, NULL) == -1)
+					Punt("Cannot open pty: %s", strerror(errno));
+			} else {
+				if (pipe(fd) == -1)
+					Punt("Cannot create pipe: %s", strerror(errno));
+			}
 			job->inPipe = fd[0];
 			job->outPipe = fd[1];
 			fcntl(job->inPipe, F_SETFD, 1);
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADe0-4mJMTuEjY9Bv0r04ET0eb2hHTZ7WvQGobGsg4XJbXfF%2BA>