autoconf-patches
[Top][All Lists]
Advanced

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

FYI: Re: washing of Perl's exit codes


From: Alexandre Duret-Lutz
Subject: FYI: Re: washing of Perl's exit codes
Date: Fri, 23 May 2003 20:11:36 +0200
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3 (gnu/linux)

>>> "Akim" == Akim Demaille <address@hidden> writes:

 Akim> Alexandre Duret-Lutz said:
 >> This completes the m4_version_prereq change by letting xsystem()
 >> propagate exit codes.  It also augment xsystem() to diagnose the
 >> case where the command was not run at all (like xsystem("Idontexist")).

 Akim> Thanks a lot!  Please, install it.  But really, _you_ don't need
 Akim> approvals.

Ok.  I just realized I sent this to automake-patches instead of
autoconf-patches.

So here is the patch again.

2003-05-23  Alexandre Duret-Lutz  <address@hidden>

        * lib/Autom4te/General.pm (END): Rewrite exit code processing.
        Do not call `_exit()', simply modify `$?'.
        (xsystem): Reset $! before running system, and check it afterward.
        * tests/tools.at (autoupdating AC_PREREQ): Expect exit status
        63 for version mismatches.

Index: lib/Autom4te/General.pm
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/General.pm,v
retrieving revision 1.24
diff -u -r1.24 General.pm
--- lib/Autom4te/General.pm     16 Oct 2002 06:38:50 -0000      1.24
+++ lib/Autom4te/General.pm     23 May 2003 16:27:13 -0000
@@ -1,5 +1,5 @@
 # autoconf -- create `configure' using m4 macros
-# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003  Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -89,34 +89,59 @@
 
 # END
 # ---
-# Exit nonzero whenever closing STDOUT fails.
-# Ideally we should `exit ($? >> 8)', unfortunately, for some reason
-# I don't understand, whenever we `exit (1)' somewhere in the code,
-# we arrive here with `$? = 29'.  I suspect some low level END routine
-# might be responsible.  In this case, be sure to exit 1, not 29.
+# Filter Perl's exit codes, delete any temporary directory, and exit
+# nonzero whenever closing STDOUT fails.
 sub END
 {
-  my $exit_status = $? ? 1 : 0;
-
-  use POSIX qw (_exit);
+  # $? contains the exit status we will return.
+  # It was set using one of the following ways:
+  #
+  #  1) normal termination
+  #     this sets $? = 0
+  #  2) calling `exit (n)'
+  #     this sets $? = n
+  #  3) calling die or friends (croak, confess...):
+  #     a) when $! is non-0
+  #        this set $? = $!
+  #     b) when $! is 0 but $? is not
+  #        this sets $? = ($? >> 8)   (i.e., the exit code of the
+  #        last program executed)
+  #     c) when both $! and $? are 0
+  #        this sets $? = 255
+  #
+  # Cases 1), 2), and 3b) are fine, but we prefer $? = 1 for 3a) and 3c).
+  $? = 1 if ($! && $! == $?) || $? == 255;
+  # (Note that we cannot safely distinguish calls to `exit (n)'
+  # from calls to die when `$! = n'.  It's not big deal because
+  # we only call `exit (0)' or `exit (1)'.)
 
   if (!$debug && defined $tmp && -d $tmp)
     {
       if (<$tmp/*>)
        {
-         unlink <$tmp/*>
-           or carp ("$me: cannot empty $tmp: $!\n"), _exit (1);
+         if (! unlink <$tmp/*>)
+           {
+             print "$me: cannot empty $tmp: $!\n";
+             $? = 1;
+             return;
+           }
+       }
+      if (! rmdir $tmp)
+       {
+         print "$me: cannot remove $tmp: $!\n";
+         $? = 1;
+         return;
        }
-      rmdir $tmp
-       or carp ("$me: cannot remove $tmp: $!\n"), _exit (1);
     }
 
   # This is required if the code might send any output to stdout
   # E.g., even --version or --help.  So it's best to do it unconditionally.
-  close STDOUT
-    or (carp "$me: closing standard output: $!\n"), _exit (1);
-
-  _exit ($exit_status);
+  if (! close STDOUT)
+    {
+      print "$me: closing standard output: $!\n";
+      $? = 1;
+      return;
+    }
 }
 
 
@@ -495,10 +520,20 @@
 
   verbose "running: $command";
 
-  (system $command) == 0
-    or error ((split (' ', $command))[0]
-             . " failed with exit status: "
-             . WEXITSTATUS ($?));
+  $! = 0;
+
+  if (system $command)
+  {
+    $command = (split (' ', $command))[0];
+    if ($!)
+      {
+       error "failed to run $command: $!";
+      }
+    else
+      {
+       error "$command failed with exit status: " . WEXITSTATUS ($?);
+      }
+  }
 }
 
 
Index: tests/tools.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/tools.at,v
retrieving revision 1.70
diff -u -r1.70 tools.at
--- tests/tools.at      22 May 2003 13:24:08 -0000      1.70
+++ tests/tools.at      23 May 2003 16:27:14 -0000
@@ -599,6 +599,6 @@
         0, [expout], [])
 
 AT_CHECK([echo "AC_PREREQ(999.99)" | autoupdate -],
-        1, [], [ignore])
+        63, [], [ignore])
 
 AT_CLEANUP

-- 
Alexandre Duret-Lutz





reply via email to

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