]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* bin/autom4te.in (&handle_m4): Protect us from corrupted file
authorAkim Demaille <akim@epita.fr>
Fri, 8 Mar 2002 11:48:17 +0000 (11:48 +0000)
committerAkim Demaille <akim@epita.fr>
Fri, 8 Mar 2002 11:48:17 +0000 (11:48 +0000)
because of C-c: have m4 output in tmp files, then mv them.

ChangeLog
bin/autom4te.in

index 49401ad7f6f42bca8c0e4928c2f50b29b5fee2dd..f12e8740fb6ad8a40f90015273fa4bc68e81d8ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-03-08  Akim Demaille  <akim@epita.fr>
+
+       * 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  <akim@epita.fr>
 
        * bin/autoconf.in, bin/autoheader.in, bin/autom4te.in,
index a2dd96ddd5bc8f50b06167c471baeeac4fb55a8b..3460523f2d98e8c43674eb8d12f545f27967b097 100644 (file)
@@ -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"
                 . ' </dev/null'
-                . " >$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";
+    }
 }