A patch was recently proposed for GNU libc to make *all* processes
start up with file descriptors 0, 1, and 2 guaranteed to be open.
Part of the rationale for this patch was that configure scripts fail
catastrophically if these fds are closed, even if you just want to run
--help or --version, e.g.
$ ./configure --version <&-; echo $?
./configure: line 555: 0: Bad file descriptor
1
configure scripts cannot rely on behavior specific to GNU libc, so
whether or not that patch gets committed, it makes sense for us to
make configure scripts robust against being started up with closed
stdin/stdout/stderr.
This patch adds code to ensure fds 0, 1, and 2 are open, early in
_AS_SHELL_SANITIZE. It uses a construct, ‘(exec 3>&n)’, that’s known
not to work in very old shells, but that’s OK because those shells
will be rejected by _AS_DETECT_BETTER_SHELL anyway. The worst-case
scenario is that the “This script requires a shell more modern than
all the shells I found on your system” error message won’t get printed.
When these fds are found not to be open, we open them on /dev/null, in
the normal I/O direction (0 for reading, 1 and 2 for writing). There
is a case for opening them in the *opposite* direction so that, for
instance, writes to fd 1 will fail when fd 1 started out closed.
However, that would expose latent bugs that I think should be dealt
with *after* 2.70. (See Savannah bug #110300 for more detail.)
I also took the opportunity to rationalize the order of operations in
_AS_SHELL_SANITIZE a little. All the special shell and environment
variables that we care about are dealt with immediately after
AS_BOURNE_COMPATIBLE, and _AS_PATH_SEPARATOR_PREPARE happens
immediately before the first use of _AS_PATH_WALK.
* lib/m4sugar/m4sh.m4 (_AS_ENSURE_STANDARD_FDS): New macro.
(_AS_SHELL_SANITIZE): Move the “Unset variables that we do not need”
and “NLS nuisances” blocks immediately after setting IFS; merge the
unsetting of CDPATH into the main unsetting loop; move invocation of
_AS_PATH_SEPARATOR_PREPARE to immediately above the “Find who we are”
block; invoke _AS_ENSURE_STANDARD_FDS immediately before
_AS_PATH_SEPARATOR_PREPARE.
* tests/base.at (configure with closed standard fds): New test.
* tests/torture.at (--help and --version in unwritable directory): New test.
This macro factors out some repeated code surrounding tests that run
make, such as honoring $MAKE, *not* honoring $MAKEFLAGS, and
normalizing the exit status. Partially addresses bug #110267
(problems with Sun’s make barfing on GNU make options from
$MAKEFLAGS).
Also addresses some unrelated problems I noticed while changing all
the tests that run make to use this macro:
The shtool test is now properly skipped if shtool is not available on
the host system.
Some of the Fortran tests would create an executable and then run it,
others would create an executable and then the AT_CHECK operation that
would run it was commented out. There’s no evidence in the changelog
or the git history for why this was done. I uncommented all of the
commented-out cases; this can be undone easily if it causes
problems. (It can’t be an issue with cross-compilation because some
of the tests do run the executable.)
* tests/local.at (AT_CHECK_MAKE): New macro wrapping an AT_CHECK
invocation of make. All tests that run make updated to use this macro.
* tests/fortran.at: Uncomment all AT_CHECKs that run the just-compiled
program.
* tests/foreign.at (shtool): Skip the test if shtool is not available
from the host system. Simplify shell logic.
It is almost always incorrect for a configure script to omit either
AC_INIT or AC_OUTPUT. Issue warnings in the ‘syntax’ category for
this.
The implementation is, unfortunately, a bit of a kludge. To check for
the _absence_ of a macro invocation, we can use m4_provide_if inside a
m4_wrap hook. However, if we activate the m4_wrap hook directly from
general.m4, we get spurious warnings at freeze time. We also get
warnings whenever a script that’s missing AC_INIT and/or AC_OUTPUT
is *traced*, which means we get double warnings from autoconf, and
autoheader and aclocal complain about it too, which seems unnecessary.
A clean way to deal with this would be to make the hook look for a
special macro that’s defined only when autoconf (the program) is
invoked without any --trace arguments. Unfortunately, autom4te
doesn’t pass --define down to M4, and changing that would involve
coordinating with Automake (the project), so instead I’ve gone for the
kludge: a new file lib/autoconf/trailer.m4 that calls m4_wrap. This
file is *not* included in autoconf.m4f, but it’s installed, and it’s
added to the m4 invocation by autoconf (the program) only when not
tracing. (It still uses m4_wrap, because we pass it to m4 *before*
configure.ac, because otherwise we get nonsense locations for any
*other* diagnostics coming out of this autoconf invocation. I don’t
know why.)
The additional checks in autoreconf are intended to make sure that if
autoreconf skips a directory entirely, you get told why.
Lots of tests in the testsuite didn’t bother with AC_OUTPUT, and
somewhat fewer didn’t bother with AC_INIT; where possible I just added
them.
Suggested by David A. Wheeler, who submitted a patch, but I didn’t
wind up using any of his code. (His implementation used an extra
tracing pass, only checked for a missing AC_INIT, and invented a new
command-line option to turn off this specific warning. I thought this
was tidier overall, despite the kludge.)
* lib/autoconf/general.m4 (_AC_FINALIZE): New macro: code to be run
when generating configure, after the entire configure.ac is
processed. Currently only checks that AC_INIT and AC_OUTPUT were
called at some point, issuing syntax-category warnings if not.
(AC_INIT, AC_OUTPUT): m4_provide self.
* lib/autoconf/trailer.m4: New file that just calls m4_wrap([_AC_FINALIZE]).
* lib/local.mk: Install new file.
* bin/autoconf.as: Add trailer.m4 to the final invocation of autom4te,
but only when not tracing.
* bin/autoreconf.in (autoreconf_current_directory): Distinguish in
diagnostics between “directory skipped because it doesn’t have a
configure.ac or configure.in” (e.g. Cygnus configure) and “directory
has a configure.ac but it doesn’t appear to be autoconf input.”
* tests/*.at: Fix all tests affected by the new warnings.
While investigating something else, I noticed that AC_REPLACE_FUNCS
calls _AH_CHECK_FUNC and AC_LIBSOURCE in the success branch of an
AC_CHECK_FUNC. This doesn’t work; both of those are marker macros
that need to be expanded unconditionally at m4 time so that traces
(placed by autoheader and automake, respectively) will fire. In order
to fix this while keeping the code readable, I would up doing a major
refactor. There are now four internal macros implementing AC_REPLACE_FUNCS.
_AC_REPLACE_FUNC_U is called unconditionally for every shell word in
the list passed to AC_REPLACE_FUNCS, and does _AH_CHECK_FUNC +
AC_LIBSOURCE if it can, or issues a warning if it can’t. (It could
make sense to make this a public function, if we think shell variables
in the AC_REPLACE_FUNCS list need to be supported long-term. I dunno
if there’s a use case that can’t be handled by AC_REPLACE_FUNCS inside
a shell conditional just as well.)
_AC_REPLACE_FUNC_L and _AC_REPLACE_FUNC_NL implement the actual test
performed for each function to be replaced; the difference is that _L
(for literal) can only be used on a function whose name is known at m4
expansion time, _NL (nonliteral) works regardless. _AC_REPLACE_FUNCS,
which already existed, handles looping either at m4 time or shell time
as appropriate. AC_REPLACE_FUNCS remains a thin wrapper that runs
_AC_REPLACE_FUNCS(m4_flatten([$1])).
The _bulk_ of the patch is changes to the testsuite so that it notices
the original bug. Specifically, AT_CHECK_AUTOHEADER now takes an
argument which is a whitespace-separated list of preprocessor macro
names that ought to appear in the generated config.h.in. This can be
set to ‘ignore’ to skip the test, and unfortunately that’s what the
“trivial” per-macro tests have to do (AT_CHECK_MACRO and friends), so
coverage is not ideal, but it’s better than what we had. Also,
AT_CHECK_M4 now normalizes the backtrace lines that appear in the
output of an AC_DIAGNOSE, e.g.
configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
configure.ac:6: You should run autoupdate.
../../lib/autoconf/lang.m4:125: AC_LANG_SAVE is expanded from...
configure.ac:6: the top level
becomes
configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
configure.ac:6: You should run autoupdate.
lang.m4: AC_LANG_SAVE is expanded from...
configure.ac:6: the top level
This allows us to write tests for these diagnostics that don’t depend
on the relationship between the source and build directories, and
won’t break when unrelated patches change the line number of a macro
definition.
* lib/autoconf/functions.m4 (AC_REPLACE_FUNCS, _AC_REPLACE_FUNCS)
(_AC_REPLACE_FUNC): Refactor into AC_REPLACE_FUNCS,
_AC_REPLACE_FUNCS, _AC_REPLACE_FUNC_U, _AC_REPLACE_FUNC_L,
_AC_REPLACE_FUNC_NL. Ensure that _AH_CHECK_FUNC and
AC_LIBSOURCE are invoked unconditionally at m4 expansion
time for each literal function name in the argument to
AC_CHECK_FUNCS. Issue warnings about non-literal names.
* tests/local.at (AT_CHECK_M4): Normalize backtrace lines from
the output of AC_DIAGNOSE / m4_warn.
(AT_CHECK_AUTOHEADER): Add arg EXPECTED-TMPLS
giving a list of preprocessor macro names that should appear
in the generated config.h.in. Use AT_CHECK_M4 to invoke autoheader.
(_AT_CHECK_AC_MACRO, AT_CHECK_MACRO, AT_CHECK_AU_MACRO):
Update uses of AT_CHECK_AUTOHEADER.
* tests/fortran.at, tests/semantics.at, tests/tools.at
* tests/torture.at: Update all uses of AT_CHECK_AUTOHEADER.
* tests/semantics.at (AC_REPLACE_FUNCS test): Make somewhat
more thorough, using new functionality of AT_CHECK_M4 and
AT_CHECK_AUTOHEADER.
Signed-off-by: Zack Weinberg <zackw@panix.com>
Done via 'make update-copyright', since all files are effectively
modified and distributed this year via public version control.
* all files: Update copyright year.
Done via 'make update-copyright', since all files are effectively
modified and distributed this year via public version control.
* all files: Update copyright year.
Do so because future automake and aclocal versions (starting from 1.13)
drop support for 'configure.in' as the name of the Autoconf input file.
Without this patch, the Autoconf testsuite experiences some spurious
failures when run with the development version of aclocal and automake
installed early enough in $PATH.
* tests/torture.at: Rename 'configure.in' to 'configure.ac' throughout.
Remove an obsolete comment about backward-compatibility.
Helped-by: Jim Meyering <jim@meyering.net>
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
* doc/autoconf.texi (Limitations of Usual Tools) <sed>: Mention
the issue.
* tests/torture.at (Substitute and define special characters):
Detect if sed cannot process 8-bit bytes in the C locale.
* THANKS: Update.
Reported by Rochan.
Signed-off-by: Eric Blake <eblake@redhat.com>
* tests/tools.at (autom4te preselections): Remove minor
redundancies in regular expressions used to grep the output
'automake --version' for test skipping.
* tests/torture.at (Configuring subdirectories)
(Unusual Automake input files): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
On a fresh default install, MirBSD ships with an automake wrapper
script that has bad behavior:
$ automake --version; echo $?
Provide an AUTOMAKE_VERSION environment variable, please
0
* tests/tools.at (autom4te preselections): Skip, rather than fail,
if 'automake --version' succeeds without printing a version when
an environment variable is not set.
* tests/torture.at (Configuring subdirectories)
(Unusual Automake input files): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
* tests/torture.at (AC_CONFIG_COMMANDS with temporary directory):
Use a relative path, rather than risking issues with /.
Reported by Ralf Wildenhues.
Signed-off-by: Eric Blake <eblake@redhat.com>
* lib/autoconf/status.m4 (_AC_OUTPUT_MAIN_LOOP)
(_AC_OUTPUT_FILES_PREPARE, _AC_OUTPUT_FILE)
(_AC_OUTPUT_HEADERS_PREPARE, _AC_OUTPUT_HEADER): Use $ac_tmp
internally, while preserving $tmp for existing users.
* tests/torture.at (AC_CONFIG_COMMANDS with temporary directory):
New test, that $tmp is available but not essential.
Signed-off-by: Eric Blake <eblake@redhat.com>
In particular, see http://austingroupbugs.net/view.php?id=221
and http://austingroupbugs.net/view.php?id=255.
* doc/autoconf.texi (Shell Substitutions) <${var+value}>: New
subsection.
<${var=literal}>: Tweak wording. Add mention of an ambiguity
allowed by POSIX.
* tests/torture.at (Substitute and define special characters):
Make test more robust; here, the outer "" is in a here-doc, and
does not violate the quoting rules of thumb just documented.
Signed-off-by: Eric Blake <eblake@redhat.com>
* tests/torture.at (Non-literal AC_CONFIG_SUBDIRS): Create a
hand-written aclocal.m4 file, so the -Werror test doesn't fail
over aclocal warnings about errors in third-party macro files.
Simplify test accordingly, calling autoreconf throughout.
Report by Bob Friesenhahn.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (AC_CONFIG_SUBDIRS): Do not assume the
argument is a single word.
* tests/torture.at (Deep Package): Extend test to cover this.
(Non-literal AC_CONFIG_SUBDIRS): New test.
* doc/autoconf.texi (Subdirectories): Add example marker.
* NEWS: Update.
Report by Bruno Haible.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* tests/torture.at (Torturing config.status)
(Substitute a 2000-byte string)
(Substitute and define special characters)
(Substitute a newline): Quote first argument in for list so
that it does not look like an assignment.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (_AC_OUTPUT_FILES_PREPARE): Be sure not
to remove references to a subdir of srcdir. Fix treatment of
multiple colon-separated VPATH entries.
* tests/torture.at (VPATH): New test.
Report by Keith Marshall.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* tests/torture.at (AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS):
Normalize nonzero status to 1 for writing to /dev/full, for HP-UX
11.31 cat which exits 2.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* tests/base.at (AC_CACHE_CHECK): Extend test.
(AC_CACHE_LOAD): New test.
* tests/torture.at (Configuring subdirectories): Also test
--config-cache with AC_CONFIG_SUBDIRS.
* doc/autoconf.texi (Caching Results): Annotate code snippets
which are tested in the test suite.
(Cache Files): Documented cache variables may be used on the
configure command line to override individual entries in the
cache file.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* doc/autoconf.texi (Autoconf Language, Generic Structures):
Do not capitalize the first word in error messages, do not end
them with a period.
* lib/autoconf/general.m4 (_AC_INIT_PARSE_ARGS, AC_MSG_FAILURE):
Likewise.
* lib/autoconf/status.m4 (_AC_OUTPUT_FILE): Likewise.
* lib/autotest/general.m4 (AT_INIT, at_fn_group_prepare):
Likewise.
* m4/m4.m4 (AC_PROG_GNU_M4): Likewise.
* tests/base.at (AC_TRY_COMMAND): Likewise.
* tests/torture.at (datarootdir workaround): Adjust expected
message.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (_AC_OUTPUT_MAIN_LOOP): Ensure we
exit with status 1 rather than with that of 'false', for
reproducibility.
(AC_OUTPUT): Ensure to exit 1 in case of config.status failure.
* tests/torture.at (Missing templates): Also test code path
for $srcdir != '.'.
Report by Tim Rice.
* lib/autoconf/status.m4 (_AC_OUTPUT_LINK): Check $ac_source,
not $srcdir, for being relative or absolute.
* tests/torture.at (AC_CONFIG_LINKS): New test.
(AC_CONFIG_LINKS and identical files): Extend test, avoid some
forks.
Report, patch and testcase example by Peter Breitenlohner.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* bin/autoreconf.in (autoreconf_current_directory): Collapse
newlines in the autoconf trace output, similar to how automake
invokes autoconf, so that newlines do not matter in the argument
to AC_CONFIG_SUBDIRS.
* tests/torture.at (Deep Package): Expose this issue in the
test.
* THANKS: Update.
Report by Nathan Schulte.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (_AC_OUTPUT_FILES_PREPARE): No need to
concatenate an empty second string, when we have exactly 148
characters to substitute.
* tests/torture.at (Substitute a 2000-byte string): Add test
exposure for runs of backslashes near the 148 character limit.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* tests/torture.at (Substitute and define special characters):
Double the backslash before the double-quote in
AC_DEFINE_UNQUOTED, as documented for here-documents.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (_AC_OUTPUT_CONFIG_STATUS): Implement
--config.
* doc/autoconf.texi (config.status Invocation): Document it.
* NEWS: Update.
* tests/torture.at (configure invocation): Test it.
Suggested several times, by several people, in the past.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/general.m4 (_AC_DEFINE_Q_PRINT): New macro.
(_AC_DEFINE_Q): Use it to avoid forks for all AC_DEFINE and most
AC_DEFINE_UNQUOTED.
* lib/autoconf/fortran.m4 (_AC_FC_WRAPPERS): Properly quote #.
* tests/torture.at (Substitute and define special characters):
(Define to a 2000-byte string): Enhance tests to cover
AC_DEFINE_UNQUOTED.
(@%:@define header templates): Enhance test to cover #.
Signed-off-by: Eric Blake <ebb9@byu.net>
* lib/autoconf/status.m4 (_AC_OUTPUT_CONFIG_STATUS): Flatten
whitespace in $ac_config_files and $ac_config_headers.
* tests/torture.at (Parameterized AC_CONFIG_FILES): New test.
Report by Andreas Schwab and Per Øyvind Karlsen.
* THANKS: Update.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/status.m4 (_AC_OUTPUT_HEADERS_PREPARE): For
undefined preprocessor macros that are followed by a comment
in the header template, do not create nested comments in the
output.
* tests/torture.at (@%:@define header templates): Extend test.
* NEWS: Update.
Report by Karsten Hopp <karsten@redhat.com>.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lib/autoconf/general.m4 (_AC_ARG_VAR_VALIDATE, AC_MSG_FAILURE):
Output $ac_pwd along with fatal failure.
* tests/torture.at (Deep Package): Extend test.
Reported numerous times against GCC, and probably other packages.