autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replace autom4te output file atomically


From: Ben Pfaff
Subject: Re: replace autom4te output file atomically
Date: Wed, 20 Aug 2008 22:47:27 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Ralf Wildenhues <address@hidden> writes:
> I'm stumbling over the testsuite failure though (and wondering
> slightly if this can in any way be a destabilizing change).
and then later:
> To reproduce it, all you need is a few tries and a file system with
> one second granularity.

Oh gosh, you're absolutely right.  I guess I just didn't run it
more than once or twice.

Ralf continues:
> The only other questions I ask myself wrt. Ben's patch is: when autoconf
> is interrupted by SIGQUIT (C-\) or KILL, then temporary files may build
> up.  Maybe this should be mentioned in the manual somewhere (just to be
> safe against user complaints later)?  Also, the amound of free space
> needed for one autoconf rerun increases now by one configure script
> size, but that's more of a theoretical question.

Eric Blake <address@hidden> comments:
> That's true of any program that uses temporary files; it seems
> like documentation is the right solution (since you obviously
> can't hook SIGKILL to do cleanup).  This could be as simple as
> adding a statement that autom4te honors $TMPDIR (defaulting to
> /tmp), and uses the namespace am4t* within that directory.
> Hmm, the manual doesn't even have an instance of @env{TMPDIR}.

My patch, as submitted, does not in fact honor $TMPDIR or use
/tmp.  It uses the same directory as the output file.  This was a
conscientious choice, though not one that I mentioned: when /tmp
is a separate file system, as it often is, it would then be
pointless to try to atomically rename the new file over the old,
since rename does not work across file systems.

An alternative approach would be to simply delete the output file
when autom4te terminates due to a signal.  This would also
accomplish the original purpose of not leaving partially created
configure scripts.  At the same time, it avoids the problems of
atomic replacement and in particular the problem of leaving
temporary file droppings upon SIGKILL etc.  Finally, the
implementation is simpler.

Here is a patch that implements this alternative approach.  I
dropped the test due to Ralf's comments.  What do you think?

commit 07cee3e070b5f9e3096c8fd7e799968b108a3055
Author: Ben Pfaff <address@hidden>
Date:   Wed Aug 20 22:35:28 2008 -0700

    * bin/autom4te.in (handle_output): Remove the output file if
    Autoconf is terminated by a signal, to avoid leaving a partially
    written output file.

diff --git a/ChangeLog b/ChangeLog
index 4c4cc3a..caffe43 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-08-11  Ben Pfaff  <address@hidden>
+
+       * bin/autom4te.in (handle_output): Remove the output file if
+       Autoconf is terminated by a signal, to avoid leaving a partially
+       written output file.
+
 2008-08-06  Eric Blake  <address@hidden>
 
        Fix autoheader 2.62 regression on AC_DEFINE([__EXTENSIONS__]).
diff --git a/bin/autom4te.in b/bin/autom4te.in
index 685df41..933505b 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -562,6 +562,15 @@ sub handle_output ($$)
   else
     {
       $out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
+      if (-f $out) {
+       $SIG{'HUP'} = $SIG{'INT'} = $SIG{'PIPE'} = $SIG{'TERM'} =
+         sub {
+           my ($signal) = @_;
+           unlink ($output);
+           $SIG{$signal} = 'DEFAULT';
+           kill ($signal, $$);
+         };
+      }
     }
   fatal "cannot create $output: $!"
     unless $out;

-- 
"A computer is a state machine.
 Threads are for people who cant [sic] program state machines."
--Alan Cox




reply via email to

[Prev in Thread] Current Thread [Next in Thread]