m4-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] bootstrap: don't exit with status 0 on errors


From: Eric Blake
Subject: Re: [PATCH] bootstrap: don't exit with status 0 on errors
Date: Sat, 21 Jul 2012 13:20:12 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 07/21/2012 12:02 PM, Stefano Lattarini wrote:
> * bootstrap (EXIT_FAILURE): Actually initialize to '1'.  Otherwise,
> the function 'func_fatal_error' will actually and unconditionally
> exit with status 0 (yikes).
> (EXIT_SUCCESS): Initialize to 0.  This missing initialization wasn't
> causing any actual bug for now, but could easily start doing so in
> the future.

Eww.  Looks like this has been around since commit 2d8b924, in Jul 2006.
 :(  And it's not the only bug; we were unconditionally invoking:

$exit_cmd $EXIT_FAILURE

which happens to be a no-op in the common case where both variables are
undefined, but would be a syntax error with your patch (unless a script
named '1' exists in your PATH) or unexpected behavior if exit_cmd were
pre-populated in the calling environment.

> 
> Copyright-paperwork-exempt: yes
> Signed-off-by: Stefano Lattarini <address@hidden>
> ---
>  bootstrap | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/bootstrap b/bootstrap
> index b5d740c..db37209 100755
> --- a/bootstrap
> +++ b/bootstrap
> @@ -49,6 +49,9 @@
>  : ${RM='rm -f'}
>  : ${SED=sed}
>  
> +EXIT_SUCCESS=0
> +EXIT_FAILURE=1

This isn't C - rather than go through indirection, we might as well just
directly use the exit values.

I'm planning on pushing this instead to branch-1.4, and I really need to
find time to bring the branch-1.6 and master branches up to speed.

From a0496f2a324727997fb35a40e6177d6c82bc6d2a Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 21 Jul 2012 13:16:52 -0600
Subject: [PATCH] bootstrap: avoid undefined variables

EXIT_SUCCESS, EXIT_FAILURE, and exit_cmd were used uninitialized,
with potentially disastrous results depending on what was inherited
in from the calling environment.

* bootstrap (func_fatal_error, func_usage, func_help)
(func_version): Use constants, not undefined variables; propagate
any write failures.
(func_missing_arg): Drop duplicate declaration.  Preinitialize
exit_cmd.
Reported by Stefano Lattarini.
---
 ChangeLog |   10 ++++++++++
 bootstrap |   24 +++++++++---------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8b186c8..631798d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-07-21  Eric Blake  <address@hidden>
+
+       bootstrap: avoid undefined variables
+       * bootstrap (func_fatal_error, func_usage, func_help)
+       (func_version): Use constants, not undefined variables; propagate
+       any write failures.
+       (func_missing_arg): Drop duplicate declaration.  Preinitialize
+       exit_cmd.
+       Reported by Stefano Lattarini.
+
 2012-06-26  Eric Blake  <address@hidden>

        build: get missing from automake, not gnulib
diff --git a/bootstrap b/bootstrap
index b5d740c..b554a57 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh

-# bootstrap (GNU M4) version 2010-03-02
+# bootstrap (GNU M4) version 2012-07-21
 # Written by Gary V. Vaughan  <address@hidden>

 # Copyright (C) 2004-2012 Free Software Foundation, Inc.
@@ -92,7 +92,7 @@ func_error ()
 func_fatal_error ()
 {
     func_error ${1+"$@"}
-    exit $EXIT_FAILURE
+    exit 1
 }

 # func_verbose arg...
@@ -120,15 +120,6 @@ func_fatal_help ()
     func_fatal_error "Try \`$progname --help' for more information."
 }

-# func_missing_arg argname
-# Echo program name prefixed message to standard error and set global
-# exit_cmd.
-func_missing_arg ()
-{
-   func_error "missing argument for $1"
-   exit_cmd=exit
-}
-
 # func_usage
 # Echo short help message to standard output and exit.
 func_usage ()
@@ -140,7 +131,7 @@ func_usage ()
     }; d' < "$progpath"
     echo
     echo "run \`$progname --help | more' for full usage"
-    exit $EXIT_SUCCESS
+    exit
 }

 # func_help
@@ -152,7 +143,7 @@ func_help ()
         s/\$progname/'$progname'/;
         p;
      }; d' < "$progpath"
-    exit $EXIT_SUCCESS
+    exit
 }

 # func_version
@@ -164,7 +155,7 @@ func_version ()
         s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
         p;
      }; d' < "$progpath"
-     exit $EXIT_SUCCESS
+     exit
 }

 # func_update
@@ -182,6 +173,9 @@ func_update ()
 # Parse options once, thoroughly.  This comes as soon as possible in
 # the script to make things like `bootstrap --version' happen quickly.
 {
+  # Detect as many errors as possible before quitting
+  exit_cmd=:
+
   # sed scripts:
   my_sed_single_opt='1s/^\(..\).*$/\1/;q'
   my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
@@ -207,7 +201,7 @@ func_update ()
   done

   # Bail if the options were screwed
-  $exit_cmd $EXIT_FAILURE
+  $exit_cmd 1

   if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
     func_fatal_error \
-- 
1.7.10.4



-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org



Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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