Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Jun 2013 20:57:03 +0200
From:      Tijl Coosemans <tijl@FreeBSD.org>
To:        "Simon J. Gerraty" <sjg@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r251422 - in head: contrib/bmake usr.bin/bmake
Message-ID:  <51C8967F.2060905@FreeBSD.org>
In-Reply-To: <201306051612.r55GCpPG050941@svn.freebsd.org>
References:  <201306051612.r55GCpPG050941@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
------enig2FEITOQXDJAXPCBPGMLER
Content-Type: multipart/mixed;
 boundary="------------030701030603070904050805"

This is a multi-part message in MIME format.
--------------030701030603070904050805
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 2013-06-05 18:12, Simon J. Gerraty wrote:
> Author: sjg
> Date: Wed Jun  5 16:12:50 2013
> New Revision: 251422
> URL: http://svnweb.freebsd.org/changeset/base/251422
>=20
> Log:
>   Update to bmake-20130604 to fix file descriptor leak.
>=20
> Modified: head/contrib/bmake/job.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/contrib/bmake/job.c	Wed Jun  5 15:52:24 2013	(r251421)
> +++ head/contrib/bmake/job.c	Wed Jun  5 16:12:50 2013	(r251422)
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $	*/
> +/*	$NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sjg Exp $	*/
> =20
>  /*
>   * Copyright (c) 1988, 1989, 1990 The Regents of the University of Cal=
ifornia.
> @@ -70,14 +70,14 @@
>   */
> =20
>  #ifndef MAKE_NATIVE
> -static char rcsid[] =3D "$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 ch=
ristos Exp $";
> +static char rcsid[] =3D "$NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sj=
g Exp $";
>  #else
>  #include <sys/cdefs.h>
>  #ifndef lint
>  #if 0
>  static char sccsid[] =3D "@(#)job.c	8.2 (Berkeley) 3/19/94";
>  #else
> -__RCSID("$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $");
> +__RCSID("$NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sjg Exp $");
>  #endif
>  #endif /* not lint */
>  #endif
> @@ -414,6 +414,15 @@ JobCreatePipe(Job *job, int minfd)
>      if (pipe(job->jobPipe) =3D=3D -1)
>  	Punt("Cannot create pipe: %s", strerror(errno));
> =20
> +    for (i =3D 0; i < 2; i++) {
> +       /* Avoid using low numbered fds */
> +       fd =3D fcntl(job->jobPipe[i], F_DUPFD, minfd);
> +       if (fd !=3D -1) {
> +	   close(job->jobPipe[i]);
> +	   job->jobPipe[i] =3D fd;
> +       }
> +    }
> +   =20
>      /* Set close-on-exec flag for both */
>      (void)fcntl(job->jobPipe[0], F_SETFD, 1);
>      (void)fcntl(job->jobPipe[1], F_SETFD, 1);

I've been noticing that bmake doesn't run parallel jobs as like fmake.
I've attached a Makefile that I think shows what's going wrong.

If you run "make -j4" it outputs the following:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
--- all ---
-j 4 -i -J 15,16
4
-j 4 -i
4
--- sub_2 ---
-j 4 -i -J 15,16
4
-j 4 -i
4
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D

Bmake outputs the target name in -j mode (e.g. "--- all ---"), but
there's no "--- sub_1 ---" and "--- sub_3 ---" which suggests -j isn't
working there. The -J flag also doesn't appear in .MAKEFLAGS in those
targets.

I suspect the descriptors for the job server have to remain open so
submakes can pick them up. At least, when I comment out the two fcntl
calls above (and two more below), I do get the output I expect:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
--- all ---
-j 4 -J 15,16
4
--- sub_1 ---
-j 4 -J 15,16
4
--- sub_2 ---
-j 4 -J 15,16
4
--- sub_3 ---
-j 4 -J 15,16
4
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D

> @@ -426,15 +435,6 @@ JobCreatePipe(Job *job, int minfd)
>       */
>      fcntl(job->jobPipe[0], F_SETFL,=20
>  	fcntl(job->jobPipe[0], F_GETFL, 0) | O_NONBLOCK);
> -
> -    for (i =3D 0; i < 2; i++) {
> -       /* Avoid using low numbered fds */
> -       fd =3D fcntl(job->jobPipe[i], F_DUPFD, minfd);
> -       if (fd !=3D -1) {
> -	   close(job->jobPipe[i]);
> -	   job->jobPipe[i] =3D fd;
> -       }
> -    }
>  }
> =20
>  /*-
> @@ -2828,6 +2828,8 @@ Job_ServerStart(int max_tokens, int jp_0
>  	/* Pipe passed in from parent */
>  	tokenWaitJob.inPipe =3D jp_0;
>  	tokenWaitJob.outPipe =3D jp_1;
> +	(void)fcntl(jp_0, F_SETFD, 1);
> +	(void)fcntl(jp_1, F_SETFD, 1);

These two fcntl calls have to be commented out too.

--------------030701030603070904050805
Content-Type: text/plain; charset=ISO-8859-15;
 name="Makefile"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="Makefile"

YWxsOgoJQGVjaG8gJHsuTUFLRUZMQUdTfQoJQGVjaG8gJHsuTUFLRS5KT0JTfQoJQCR7TUFL
RX0gc3ViXzEKCnN1Yl8xOgoJQGVjaG8gJHsuTUFLRUZMQUdTfQoJQGVjaG8gJHsuTUFLRS5K
T0JTfQoJQCR7TUFLRX0gc3ViXzIKCnN1Yl8yOgoJQGVjaG8gJHsuTUFLRUZMQUdTfQoJQGVj
aG8gJHsuTUFLRS5KT0JTfQoJQCR7TUFLRX0gc3ViXzMKCnN1Yl8zOgoJQGVjaG8gJHsuTUFL
RUZMQUdTfQoJQGVjaG8gJHsuTUFLRS5KT0JTfQoK
--------------030701030603070904050805--

------enig2FEITOQXDJAXPCBPGMLER
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (FreeBSD)

iF4EAREIAAYFAlHIloMACgkQfoCS2CCgtiubrAD8CCgC91+tMcY855SSDCDOMGvd
78FzNF2fRVuoexvUmjMA/A99PKOLevE/d61PNt1tnfnxEcd2Uk8oS+HuhFElvf/a
=7HT0
-----END PGP SIGNATURE-----

------enig2FEITOQXDJAXPCBPGMLER--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51C8967F.2060905>