autoconf-patches
[Top][All Lists]
Advanced

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

OpenBSD shell, errexit, and && in if clause


From: Ralf Wildenhues
Subject: OpenBSD shell, errexit, and && in if clause
Date: Mon, 1 May 2006 13:53:13 +0200
User-agent: Mutt/1.5.11+cvs20060403

[ upstream report:
  http://cvs.openbsd.org/cgi-bin/query-pr-wrapper?full=yes&numbers=5093
]

OpenBSD /bin/sh aka /bin/ksh has an interesting bug: the second "false"
in the script below wrongly causes the shell to exit, but not the first
one, so "two" isn't printed.

#! /bin/sh
set -e
false && exit 1
echo one
if :; then
  false && exit 1
fi
echo two

It doesn't matter if "false" is a builtin here, or replaced by an
external process that happens to fail.  Same issue with a "for" loop
(but, surprisingly, not with an "until" loop).

OK to apply these patches to Autoconf and Automake, respectively?
Apologies to Alexandre for changing the same lines of depcomp[67].test
for the third time; at least now I have a good reason to do so.  ;-)

I have scanned Automake/tests/* and Autoconf and not found any other
instances of this at a glance.

Cheers,
Ralf

Autoconf:
        * doc/autoconf.texi (Limitations of Builtins): Mention OpenBSD
        /bin/sh -e issues with failing commands in if clauses.

Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1002
diff -u -r1.1002 autoconf.texi
--- doc/autoconf.texi   28 Apr 2006 04:17:51 -0000      1.1002
+++ doc/autoconf.texi   28 Apr 2006 16:27:59 -0000
@@ -12168,6 +12321,24 @@
 The @command{set} of the address@hidden 6.0 shell does not sort its
 output.
 
+The address@hidden 4.8 shell wrongly exits if a command in an @samp{&&}
+list fails inside an @samp{if} clause or @samp{for} loop:
+
address@hidden
+#! /bin/sh
+set -e
+false && exit 1
+echo one
+if :; then
+  false && exit 1
+fi
+echo two
address@hidden example
+
address@hidden
+does not print @samp{two}.  A workaround is to use another if clause:
address@hidden false; then exit 1; fi}.
+
 
 @item @command{shift}
 @c ------------------


Automake:
        * tests/depcomp6.test, tests/depcomp7.test: Cater for OpenBSD
        /bin/sh -e issue with failing commands in if clauses.

Index: tests/depcomp6.test
===================================================================
RCS file: /cvs/automake/automake/tests/depcomp6.test,v
retrieving revision 1.3
diff -u -r1.3 depcomp6.test
--- tests/depcomp6.test 23 Mar 2006 06:30:06 -0000      1.3
+++ tests/depcomp6.test 28 Apr 2006 16:16:57 -0000
@@ -98,6 +98,6 @@
   cd sub2
   $sleep
   echo 'choke me' > sub3/ba3.h
-  $MAKE && exit 1
+  if $MAKE; then exit 1; fi
 fi
 :
Index: tests/depcomp7.test
===================================================================
RCS file: /cvs/automake/automake/tests/depcomp7.test,v
retrieving revision 1.3
diff -u -r1.3 depcomp7.test
--- tests/depcomp7.test 23 Mar 2006 06:30:06 -0000      1.3
+++ tests/depcomp7.test 28 Apr 2006 08:15:56 -0000
@@ -100,6 +100,6 @@
   cd sub2
   $sleep
   echo 'choke me' > sub3/ba3.h
-  $MAKE && exit 1
+  if $MAKE; then exit 1; fi
 fi
 :




reply via email to

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