From: Akim Demaille Date: Fri, 8 Mar 2002 11:48:17 +0000 (+0000) Subject: * bin/autom4te.in (&handle_m4): Protect us from corrupted file X-Git-Tag: AUTOCONF-2.53~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4473c82aad104f6f3dc33a187c7567c561f084f;p=thirdparty%2Fautoconf.git * bin/autom4te.in (&handle_m4): Protect us from corrupted file because of C-c: have m4 output in tmp files, then mv them. --- diff --git a/ChangeLog b/ChangeLog index 49401ad7f..f12e8740f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-03-08 Akim Demaille + + * bin/autom4te.in (&handle_m4): Protect us from corrupted file + because of C-c: have m4 output in tmp files, then mv them. + + 2002-03-08 Akim Demaille * bin/autoconf.in, bin/autoheader.in, bin/autom4te.in, diff --git a/bin/autom4te.in b/bin/autom4te.in index a2dd96ddd..3460523f2 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -593,7 +593,7 @@ sub handle_m4 ($@) map { split /,/ } @warning)); # GNU m4 appends when using --error-output. - unlink ($tcache . $req->id); + unlink ($tcache . $req->id . "t"); # Run m4. # @@ -601,15 +601,18 @@ sub handle_m4 ($@) # # Be extremely cautious to reverse the includes when talking to M4: # it doesn't speak the same --include as we do. + # + # We don't output directly to the cache files, to avoid problems + # when we are interrupted (that leaves corrupted files). my $command = ("$m4" . join (' --include=', '', reverse @include) . " --define=m4_warnings=$m4_warnings" . ' --debug=aflq' - . " --error-output=$tcache" . $req->id + . " --error-output=$tcache" . $req->id . "t" . join (' --trace=', '', sort @macro) . " @ARGV" . ' $ocache" . $req->id); + . " >$ocache" . $req->id . "t"); verbose "running: $command"; system $command; if ($?) @@ -617,6 +620,15 @@ sub handle_m4 ($@) verbose "$m4: failed with exit status: " . ($? >> 8) . "\n"; exit $? >> 8; } + + # Everything went ok: preserve the outputs. + foreach ($tcache, $ocache) + { + use File::Copy; + $_ .= $req->id; + move ("${_}t", "$_") + or die "$me: cannot not rename ${_}t as $_: $!\n"; + } }