* src/main.c (main): Set jobserver permissions before re-execing

Fixes an issue seen in the Linux kernel build system, reported by
Masahiro Yamada <yamada.masahiro@socionext.com>.  Fix suggested
on the bug-make mailing list by Mike Shal <marfey@gmail.com>.
* tests/scripts/features/parallelism: Add a test to verify this.
This commit is contained in:
Paul Smith 2018-09-15 14:48:57 -04:00
parent 8fd614e238
commit d603b2e6ac
2 changed files with 41 additions and 0 deletions

View File

@ -2461,6 +2461,9 @@ main (int argc, char **argv, char **envp)
fflush (stdout);
fflush (stderr);
/* The exec'd "child" will be another make, of course. */
jobserver_pre_child(1);
#ifdef _AMIGA
exec_command (nargv);
exit (0);
@ -2491,6 +2494,9 @@ main (int argc, char **argv, char **envp)
#endif
exec_command ((char **)nargv, environ);
#endif
/* We shouldn't get here but just in case. */
jobserver_post_child(1);
free (aargv);
break;
}

View File

@ -188,6 +188,41 @@ file2: file1 ; @touch $@
rmfiles('file1', 'file2', 'file3', 'file4');
# Ensure that the jobserver is preserved across make re-exec.
run_make_test(q!
all: one two
one: ;@ #PERL# jhelp.pl -w TWO -f ONE
two: ;@ #PERL# jhelp.pl -f TWO
include fff1.mk
fff1.mk: ; touch $@
!,
'-j2', "touch fff1.mk\nTWO\nONE\n");
unlink('fff1.mk', 'ONE', 'TWO');
# Test if a sub-make needs to re-exec and the makefile is built via
# sub-make. Reported by Masahiro Yamada <yamada.masahiro@socionext.com>
run_make_test(q!
all: ; @$(MAKE) -f #MAKEFILE# recurse
recurse: one two ; @echo $@
one: ;@ #PERL# jhelp.pl -w TWO -f ONE
two: ;@ #PERL# jhelp.pl -f TWO
mkinclude: ; touch fff1.mk
ifeq ($(MAKECMDGOALS),recurse)
include fff1.mk
fff1.mk: ; @$(MAKE) -f #MAKEFILE# mkinclude
endif
!,
'--no-print-directory -j2', "touch fff1.mk\nTWO\nONE\nrecurse\n");
unlink('fff1.mk', 'ONE', 'TWO');
# Make sure that all jobserver FDs are closed if we need to re-exec the
# master copy.
#