]> git.ipfire.org Git - thirdparty/autoconf.git/commit
autom4te: replace output file atomically (#110305)
authorBen Pfaff <pfaffben@debian.org>
Tue, 10 Nov 2020 14:42:58 +0000 (09:42 -0500)
committerZack Weinberg <zackw@panix.com>
Tue, 10 Nov 2020 14:42:58 +0000 (09:42 -0500)
commit1725c947144d9bebfe7817c2c5f0d53d884b1297
treea716ad63e2d39c1768fdea2b7ec8e002dd591cbc
parent29df8097dd854707c2b456f02f05d2995340c351
autom4te: replace output file atomically (#110305)

In 2003, Joey Hess reported the following bug against Debian's
autoconf package (see http://bugs.debian.org/221483):

    I noticed that if I ctrl-c autoconf, it can leave a partially
    written, executable configure script. I was lucky enough to
    get a configure script that exited with a shell parse error,
    but if I had been unlucky, it might have exited 0 without
    doing all the tests I expected it to do.  That would have
    sucked to ship to users.

    There are many ways to update a file in a way that is not
    prone to these problems, and I suggest that autoconf adopt
    one of them.

Ben Pfaff wrote a patch to make autom4te replace the output file
atomically; Debian has carried it since 2006.  He submitted it
to autoconf upstream in 2008 but it never went anywhere.

I (Zack) have dusted off the patch and made some minor improvements:
using File::Temp (with DIR set to the directory of the output file)
instead of a predictable temporary file name, and using
Autom4te::FileUtils::update_file instead of File::Copy::move.

I do not attempt to test the fix (the test would be inherently racey)
nor do I have autom4te delete the temp file if it crashes while the
file is being written (there is no way to do this with 100%
reliability and it strikes me as likely to cause more problems than it
solves).

Fixes our bug #110305.

* bin/autom4te.in (handle_output): When $output is to a regular or
  nonexistent file, write to a temporary file in the same directory
  and then rename it over $output after completion.
bin/autom4te.in