+2008-12-03 Eric Blake <ebb9@byu.net>
+
+ Improve AC_STATE_SAVE.
+ * tests/local.at (AC_STATE_SAVE): Avoid ls -1, and use one less
+ process by hoisting the uniqueness check into sed.
+ * doc/autoconf.texi (Limitations of Usual Tools) <ls>: Mention
+ MacOS bug.
+
2008-12-02 Eric Blake <ebb9@byu.net>
Avoid MacOS readdir bug in testsuite.
@samp{.c} files. This is no longer a practical problem, since current
@command{ls} implementations send diagnostics to standard error.
+The behavior of @command{ls} on a directory that is being concurrently
+modified is not always predictable, because of a data race where cached
+information returned by @code{readdir} does not match the current
+directory state. In fact, MacOS 10.5 has an intermittent bug where
+@code{readdir}, and thus @command{ls}, sometimes lists a file more than
+once if other files were added or removed from the directory immediately
+prior to the @command{ls} call. Since @command{ls} already sorts its
+output, the duplicate entries can be avoided by piping the results
+through @code{uniq}.
+
@anchor{mkdir}
@item @command{mkdir}
@c ------------------
# confirm that no test modifies variables outside the Autoconf namespace or
# leaves temporary files. AT_CONFIG_CMP uses the variable dumps to confirm that
# tests have the same side effects regardless of caching.
-# The sort -u is necessary, since MacOS 10.5 has a bug where readdir can
-# list a file multiple times in a rapidly changing directory.
+#
+# The sed script duplicates uniq functionality (thanks to 'info sed
+# uniq' for the recipe), in order to avoid a MacOS 10.5 bug where
+# readdir can list a file multiple times in a rapidly changing
+# directory, while avoiding yet another fork.
m4_defun([AC_STATE_SAVE],
[(set) 2>&1 | sort >state-env.$][1
-ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort -u >state-ls.$][1
+ls | sed '/^at-/d;/^state-/d;/^config\./d
+ h
+ :b
+ $b
+ N
+ /^\(.*\)\n\1$/ {
+ g
+ bb
+ }
+ $b
+ P
+ D' >state-ls.$][1
])# AC_STATE_SAVE
]])