[SV 63333] Be more lenient when failing to create temporary files

If make cannot create a temporary lock file for output sync, continue
without output sync enabled rather than dying.

However, if make cannot store a makefile from stdin to a temporary
file that is still a fatal error.

* misc.c (get_tmppath): Keep running on failure to generate a
temporary file name.
(get_tmpfd): Keep running on failure to get a temporary file.
(get_tmpfile): Keep running on failure to open a temporary file.
Ensure memory is freed if we return an error.
* posixos.c (os_anontmp): Keep running on failure to open an
anonymous temporary file.
* output.c (setup_tmpfile): Print an error on failure to create an
output sync lock file.
* main.c (main): Die on failure to store makefile from stdin to a
temporary file.
* tests/scripts/features/output-sync: Add tests.
* tests/scripts/features/temp_stdin: Ditto.
This commit is contained in:
Dmitry Goncharov
2022-11-13 16:20:33 -05:00
committed by Paul Smith
parent 4c9d87f4ae
commit 1b51ba1f5d
6 changed files with 89 additions and 21 deletions

View File

@@ -363,8 +363,24 @@ pid:=$(shell echo $$PPID)
all:; @#HELPER# term $(pid) sleep 10
!, '-O -j2', '/#MAKE#: \*\*\* \[#MAKEFILE#:3: all] Terminated/', POSIX::SIGTERM);
}
unlink($fout);
# SV 63333. Test that make continues to run without output sync when we
# cannot create a temporary file.
# Create a non-writable temporary directory.
# Run the test twice, because run_make_test cannot match a regex againt a
# multiline input.
my $tdir = 'test_tmp_dir';
mkdir($tdir, 0500);
$ENV{'TMPDIR'} = $tdir;
run_make_test(q!
all:; $(info hello, world)
!, '-Orecurse', "/suppressing output-sync/");
run_make_test(undef, '-Orecurse', "/#MAKE#: 'all' is up to date./");
rmdir($tdir);
}
# This tells the test driver that the perl test script executed properly.

View File

@@ -109,6 +109,21 @@ force:
@make_command = @make_orig;
unlink($makecopy);
rmdir($tmakedir);
# SV 63333. Test that make exits with an error message if we cannot store a
# makefile from stdin to a temporary file.
# Create a non-writable temporary directory.
my $tdir = 'test_tmp_dir';
mkdir($tdir, 0500);
$ENV{'TMPDIR'} = $tdir;
close(STDIN);
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
run_make_test(q!
all:; $(info hello, world)
!, '-f-', '/cannot store makefile from stdin to a temporary file. Stop./', 512);
rmdir($tdir);
}
close(STDIN);