* m4/memchr.m4 (gl_FUNC_MEMCHR): Detect glibc 2.11.2 failure on
Alpha.
* doc/posix-functions/memchr.texi (memchr): Tweak wording.
* tests/test-memchr.c (main): Enhance test.
Reported by Nelson H. F. Beebe.
Paul Eggert [Tue, 14 Sep 2010 16:03:55 +0000 (09:03 -0700)]
fts, getcwd, glob: audit for dirfd returning -1
* lib/fts.c (opendir): Remove #define; no longer used.
(opendirat): New arg PDIR_FD. All callers changed.
(fts_build, _opendir2): Use new opendirat to avoid the need for
dirfd, or for checking whether dirfd returns a negative value.
Don't use opendir; always use openat followed by fdopendir.
* lib/getcwd.c (__getcwd): Don't reset fd; fdopendir no longer clobbers
it.
* lib/glob.c (link_exists_p): Add comment explaining why dirfd never
returns -1 here.
* modules/fts (Depends-on): Remove dirfd.
* modules/getcwd (Depends-on): Likewise.
Paul Eggert [Mon, 13 Sep 2010 19:38:41 +0000 (12:38 -0700)]
fts: use O_NOFOLLOW to avoid race condition when opening a directory
* lib/fts.c (opendirat): New arg extra_flags.
(__opendir2): Use it to avoid following symlinks when opening
a directory, if symlinks are not supposed to be followed. See
<http://lists.gnu.org/archive/html/bug-gnulib/2010-09/msg00213.html>.
Paul Eggert [Mon, 13 Sep 2010 19:21:47 +0000 (12:21 -0700)]
fdopendir: preserve argument fd before returning
* lib/fdopendir.c: Adjust comments to say POSIX, not Solaris.
(fdopendir_with_dup, fd_clone_opendir): New static functions.
(fdopendir): Use them, arranging for FD to be open to the same
directory that it was when it started. (It might be temporarily
closed while fdopendir is running, so this not thread- or
signal-safe.) Be careful to do the right thing even when file
descriptors are scarce and dup fails with errno == EMFILE. See
<http://lists.gnu.org/archive/html/bug-gnulib/2010-09/msg00208.html>.
Paul Eggert [Sun, 12 Sep 2010 21:21:52 +0000 (14:21 -0700)]
savedir: add streamsavedir, deprecate fdsavedir
* NEWS: Mention deprecation of fdsavedir.
* lib/savedir.c (streamsavedir): New extern function, whose name
ends in "savedir" to be consistent with the others. This differs
from savedirstream in that it doesn't close its argument. The
next version of GNU tar will use this instead of fdsavedir, to
avoid some race conditions and conserve file descriptors.
(savedirstream): Reimplement as a wrapper around streamsavedir.
(fdsavedir): Add a comment deprecating this function. As far as
I know, only GNU tar used it, and GNU tar doesn't need it any more.
* lib/savedir.h (streamsavedir): New decl.
(fdsavedir): Add a comment deprecating this.
Paul Eggert [Fri, 10 Sep 2010 18:55:27 +0000 (11:55 -0700)]
fcntl-h: define O_CLOEXEC and O_EXEC if not defined; use new defines
* doc/posix-headers/fcntl.texi (fcntl.h): Document that
O_CLOEXEC is now defined to 0 if it is not defined, like other flags.
Also, O_EXEC is now defined to be O_RDONLY if O_EXEC is not defined.
Similarly for O_SEARCH; this last was already true, but not documented.
* lib/fcntl.in.h (O_CLOEXEC): Define to 0 if not defined.
* lib/dup-safer-flag.c (O_CLOEXEC): Remove now-useless #define.
* lib/dup3.c, lib/pipe2.c, tests/test-dup-safer.c, tests/test-fcntl.c:
Likewise.
* lib/popen-safer.c (open_noinherit): Check whether O_CLOEXEC
is zero, not whether it is defined.
* tests/test-dup3.c, tests/test-pipe2.c (main): Likewise.
* lib/progreloc.c (find_executable): Use O_EXEC rather than O_RDONLY.
* lib/open.c (open): Check for O_SEARCH as well as for O_RDONLY.
Bruno Haible [Fri, 10 Sep 2010 10:02:44 +0000 (12:02 +0200)]
pty, readutmp: Fix for FreeBSD 8.0 and OpenBSD 4.6.
* doc/glibc-functions/login_tty.texi: Mention the include file problem
on FreeBSD 8.0 and OpenBSD 4.6.
* lib/pty.in.h: Include <sys/types.h> before <libutil.h>.
* m4/pty_h.m4 (gl_PTY_H): Likewise.
* m4/pty.m4 (gl_FUNC_FORKPTY, gl_FUNC_OPENPTY): Likewise.
* m4/readutmp.m4 (gl_READUTMP): Include <sys/types.h> before <utmp.h>.
Invoke AC_INCLUDES_DEFAULT instead of using the undocumented variable
ac_includes_default.
Reported by Mats Erik Andersson <mats.andersson@gisladisker.se>.
Eric Blake [Thu, 9 Sep 2010 23:05:15 +0000 (17:05 -0600)]
strsignal: work around NetBSD bug
* m4/strsignal.m4 (gl_FUNC_STRSIGNAL): Also check in <unistd.h>.
* lib/string.in.h (includes): Likewise.
* doc/posix-functions/strsignal.texi (strsignal): Document the
bug.
Reported by Nelson H. F. Beebe.
Jim Meyering [Wed, 8 Sep 2010 20:24:22 +0000 (22:24 +0200)]
init.sh: penalize a set-x-impaired shell; don't disqualify it
* tests/init.sh: Too many shells corrupt application stderr when
you set -x, so we can't afford to disqualify them, since at least
on Irix-6.5, that would disqualify all bourne shells.
Instead, use a more discerning approach.
When iterating through candidate shells, give each a score
of 10 for perfect, 9 if corrupts stderr upon set -x but passes
all other tests, and some other value if it is unacceptable.
Use the first shell that gets a score of 10.
If no shell scores 10, use the first that scored 9.
Finally, when VERBOSE=yes is requested and set -x might cause trouble, simply
issue a warning and refrain from enabling debug output.
Eric Blake [Thu, 2 Sep 2010 03:34:44 +0000 (21:34 -0600)]
strtod: work around IRIX 6.5 bug
IRIX mis-parses "1e 1" as 10.0 and "" instead of 1.0 and "e 1".
Because the original parse may differ from the reparse in terms
of whether the value overflows, we have to do an errno dance.
* lib/strtod.c (strtod): Reparse number on shorter string if
exponent parse was invalid.
* tests/test-strtod.c (main): Add check for "0x1p 2".
Reported by Tom G. Christensen.
Jim Meyering [Wed, 8 Sep 2010 13:18:46 +0000 (15:18 +0200)]
init.sh: disqualify shells for which set -x corrupts stderr
* tests/init.sh: Add a test to disqualify /bin/sh from SunOS 5.11
and OpenBSD 4.7. They make it so with "set -x", environment settings
appear in stderr output. For example, this command:
/bin/sh -c 'set -x; P=1 true 2> err' 2>/dev/null; cat err
prints "P=1" on those two systems:
Bruno Haible [Wed, 8 Sep 2010 08:44:26 +0000 (10:44 +0200)]
gnulib-tool: Avoid stderr output on IRIX related to 'alias', 'unalias'.
* gnulib-tool: Use stderr redirection around the 'alias' and 'unalias'
commands, because some shells ignore redirections when there is an
error in the command lookup.
Reported by Eric Blake.
Bruno Haible [Sat, 4 Sep 2010 16:39:03 +0000 (18:39 +0200)]
gnulib-tool: Change --import. New options --add/remove-import.
* gnulib-tool: New options --add-import, --remove-import.
(func_usage): Document them.
(have_associative): Define always.
(func_import): In import mode, don't merge the specified settings with
the cached settings. Implement remove-import mode.
* doc/gnulib-tool.texi (Modified imports): Mention the new options.
Explain when to use them versus --import.
(Simple update): Use --add-import instead of --import.
* NEWS: Mention the change.
Jim Meyering [Sat, 4 Sep 2010 16:16:04 +0000 (18:16 +0200)]
maint.mk: avoid obscure sc_copyright_check failure in coreutils
* top/maint.mk (v_etc_file): Prepend $(gnulib_dir)/, to avoid
false positives (whose names may be ill-chosen) when searching
non-VC'd files. Otherwise, a file named "a b/lib/version-etc.c"
would cause a false-positive.
Jim Meyering [Sat, 4 Sep 2010 15:43:39 +0000 (17:43 +0200)]
avoid coreutils "make distcheck" failure
Coreutils tests with an absolute build directory name that contains
a space. Not quoting this directory name caused a failure.
* tests/test-vc-list-files-git.sh: Quote PATH dir name.
* tests/test-vc-list-files-cvs.sh: Likewise.
Bruno Haible [Sat, 4 Sep 2010 11:58:02 +0000 (13:58 +0200)]
update-copyright test: Improve output when perl is missing or too old.
* tests/test-update-copyright.sh: Move test of Perl version down after
the test whether Perl exists. Provide an explanation relating Perl's
error message to Automake's SKIP: message.
Bruno Haible [Sat, 4 Sep 2010 09:16:43 +0000 (11:16 +0200)]
Set PATH_SEPARATOR the same way autoconf does.
* build-aux/relocatable.sh.in (func_find_curr_installdir): Determine
the value of PATH_SEPARATOR the same way autoconf-generated configure
scripts do.
* m4/lib-ld.m4 (AC_LIB_PROG_LD): Likewise.
* m4/progtest.m4 (AM_PATH_PROG_WITH_TEST): Likewise.
* gnulib-tool (func_gnulib_dir): Determine the value of PATH_SEPARATOR
the same way autoconf-generated configure scripts do.
* posix-modules: Likewise.
Eric Blake [Thu, 2 Sep 2010 19:49:41 +0000 (13:49 -0600)]
tests: init.sh improvements for re-exec'ing with zsh
Tom's IRIX setup had a broken bash, and proceeded to run zsh
outside of POSIX mode. But trying to trace that setup proved
difficult, since the re-exec lost tracing.
* tests/init.sh: Borrow autoconf POSIX-mode sanitization. Pass
-vx through shell re-exec.
Reported by Tom G. Christensen.
Bruno Haible [Thu, 2 Sep 2010 09:15:39 +0000 (11:15 +0200)]
wctype: Avoid compilation error on IRIX 6.5.30.
* lib/wctype.in.h (iswblank): Declare with a replacement if
REPLACE_ISWBLANK is set.
* m4/wctype_h.m4 (gl_WCTYPE_H): Check also whether iswblank is
declared. Set REPLACE_ISWBLANK.
* modules/wctype (Makefile.am): Substitute REPLACE_ISWBLANK.
* doc/posix-functions/iswblank.texi: Mention the IRIX 6.5.30 problem.
* doc/posix-headers/wctype.texi: Likewise.
Reported by Tom G. Christensen <tgc@jupiterrise.com>.
Paul Eggert [Wed, 1 Sep 2010 20:45:53 +0000 (13:45 -0700)]
fcntl-h, etc.: prefer O_SEARCH to O_RDONLY when applicable
POSIX 2008 specifies a new 'open' flag O_SEARCH, which can be used
when one needs search access to a directory but not read access.
On systems where it is available, it works in some cases where
O_RDONLY does not, namely on directories that are searchable but
not readable, and which need only to be searchable. If O_SEARCH
is not available, fall back to the traditional method of using
O_RDONLY.
* lib/fcntl.in.h (O_SEARCH): #define to O_RDONLY if not defined.
* lib/chdir-long.c (cdb_advance_fd): Use O_SEARCH, not O_RDONLY,
when opening a directory that needs only to be searchable.
* lib/chdir-safer.c (chdir_no_follow): Likewise.
* lib/fts.c (diropen, fts_open, fd_ring_check): Likewise.
* lib/openat-proc.c (openat_proc_name): Likewise.
* lib/openat.c (openat_needs_fchdir): Likewise.
* lib/save-cwd.c (save_cwd): Likewise.
* lib/savewd.c (savewd_save, savewd_chdir): Likewise.
Eric Blake [Tue, 31 Aug 2010 08:10:32 +0000 (10:10 +0200)]
hash: factor, and guard against misbehaving hasher function
* lib/hash.c (safe_hasher): New function, to encapsulate the checking
of table->hasher's return value. Also protect against a hash value
so large that adding it to table->bucket results in a NULL pointer.
(hash_lookup, hash_get_next, hash_find_entry, transfer_entries):
Use it in place of open-coded check-and-abort.
read-file: Avoid memory reallocations with regular files.
* lib/read-file.c: Include <sys/stat.h>, <stdio.h>, <stdint.h>.
(fread_file): With regular files, use the remaining length as the
initial buffer size. Check against overflow.
* modules/read-file (Depends-on): Add ftello, malloc-posix, stdint,
sys_stat.