Eric Blake [Tue, 8 Dec 2009 04:08:17 +0000 (21:08 -0700)]
dup2: fix logic bugs
If the platform has dup2, don't register with fchdir if the
destination was -1.
If the platform lacks dup2 (are there any these days?), then don't
close the destination unless the source is valid, make sure errno
is correct, and only register with fchdir on fcntl (since dup is
already overridden to do a registration).
* lib/dup2.c (dup2): Fix logic bugs. Use HAVE_DUP2 rather than
REPLACE_DUP2 to decide when rpl_dup2 is needed.
* m4/dup2.m4 (gl_REPLACE_DUP2): Only define REPLACE_DUP2 when dup2
exists.
(gl_FUNC_DUP2): Drop unneeded AC_SUBST.
Eric Blake [Mon, 7 Dec 2009 17:17:07 +0000 (10:17 -0700)]
unistd-safer: add unit test
Add more unit tests. Meanwhile, fix compilation error on mingw when
testing unistd-safer and fchdir together; and avoid gcc warning on
platforms without setmode.
Eric Blake [Mon, 7 Dec 2009 13:53:59 +0000 (06:53 -0700)]
cloexec: preserve text vs. binary across dup_cloexec
On mingw, dup_cloexec mistakenly converted a text fd into a
binary fd. Cygwin copied the source mode. Most other platforms
don't distinguish between modes.
* lib/cloexec.c (dup_cloexec) [W32]: Query and use translation
mode.
* modules/dup2-tests (Depends-on): Add binary-io.
* modules/cloexec-tests (Depends-on): Likewise.
* tests/test-dup2.c (setmode, is_mode): New helpers.
(main): Add tests that translation mode is preserved.
* tests/test-cloexec.c (setmode, is_mode, main): Likewise.
Reported by Bruno Haible.
Eric Blake [Fri, 4 Dec 2009 21:07:58 +0000 (14:07 -0700)]
mgetgroups: reduce duplicate listings
POSIX doesn't guarantee whether the effective gid is included in
the list of supplementary groups returned by getgroups. On the
other hand, some platforms include the effective gid twice in
the list. Meanwhile, mgetgroups can independently add a duplicate.
Rather than spend a full-blown O(n log n) cleanup, we just remove
the most common forms of duplicate groups with an O(n) pass.
* lib/mgetgroups.c (mgetgroups): Reduce duplicates from the
resulting array.
* tests/test-chown.h (test_chown): Simplify client.
* tests/test-lchown.h (test_lchown): Likewise.
Eric Blake [Sat, 5 Dec 2009 13:39:09 +0000 (06:39 -0700)]
pipe2-safer: new module
pipe2 deserves a *_safer variant. It also makes the code in
pipe.c look simpler.
* modules/pipe2-safer: New file.
* lib/unistd-safer.h (pipe2_safer): New prototype.
* lib/unistd--.h (pipe2): New wrapper.
* lib/pipe-safer.c (pipe2_safer): New function.
* modules/pipe (Depends-on): Add pipe2-safer.
* lib/pipe.c (create_pipe) [WIN32]: Let pipe2_safer do the work.
Eric Blake [Sat, 5 Dec 2009 05:10:44 +0000 (22:10 -0700)]
cloexec: add dup_cloexec
This is needed to enforce correct semantics of mkostemp_safer.
Meanwhile, it is one step closer to providing O_CLOEXEC support
to open, as well as implementing portions of fcntl for mingw.
* lib/cloexec.h (dup_cloexec): New prototype. Add copyright
header and comments.
* lib/cloexec.c (set_cloexec_flag): Add comments.
(dup_cloexec): New function, with mingw implementation borrowed
from...
* lib/w32spawn.h (dup_noinherit): ...here.
* modules/execute (Depends-on): Add cloexec.
* modules/pipe (Depends-on): Likewise.
* modules/cloexec (Depends-on): Add dup2.
* modules/cloexec-tests (Files): New file.
* tests/test-cloexec.c: Likewise.
Eric Blake [Sat, 5 Dec 2009 16:24:54 +0000 (09:24 -0700)]
test-xalloc-die: fix test for mingw
When cross-compiling on mingw to target mingw, argv[0] still includes
a .exe suffix. Rather than worry about ${EXEEXT}, just add a sed
post-process. Also, simplify the script by using tests/init.sh.
* modules/xalloc-die-tests (Files): Add tests/init.sh.
* tests/test-xalloc-die.sh: Rewrite to use init.sh. Strip
directory and .exe suffix off argv[0] output.
Jim Meyering [Sat, 5 Dec 2009 08:35:28 +0000 (09:35 +0100)]
maint.mk: news-check: use grep -E
* top/maint.mk (today): Define a Make variable, not a...
(news-date-check): ...shell variable.
(news-check-regexp): Use the Make variable.
Use grep's -E option. Change the failing diagnostic to mention
the variable, $(news-check-regexp).
(news-check): Rename target from news-date-check. Update sole use.
Eric Blake [Fri, 4 Dec 2009 15:26:23 +0000 (08:26 -0700)]
mgetgroups: add xgetgroups, and avoid ENOSYS failures
ENOSYS implies that there are no supplemental groups, so we can
treat it the same as a return of 0 from getgroups rather than
exposing failure to the user. This in turn fixes a crash in
coreutils' id, which freed an uninitialized pointer.
* lib/mgetgroups.h (xgetgroups): New prototype.
* lib/mgetgroups.c (xgetgroups): New wrapper.
(mgetgroups): Handle ENOSYS.
* modules/mgetgroups (Depends-on): Add realloc.
Reported by Scott Harrison <scott.gnu.2009@scottrix.co.uk>.
Jim Meyering [Tue, 1 Dec 2009 11:06:34 +0000 (12:06 +0100)]
fts: fts_open: do not let an empty string cause immediate failure
This is required in support of GNU rm, for which the command
"rm A '' B" must process and remove both A and B, in spite of
the empty string argument.
* lib/fts.c (fts_open): Do not let the presence of an empty string
cause fts_open to fail immediately. Most fts-using tools must be
able to process all arguments, in order, and can be expected to
diagnose such arguments themselves.
Also, move declaration of local, "len", "down" to initialization.
Pádraig Brady [Mon, 30 Nov 2009 12:29:03 +0000 (12:29 +0000)]
bootstrap: fix handling of various perl --version formats
* build-aux/bootstrap (get_version): Don't use perl's $] special
variable, as that requires updating all bootstrap.conf files to
use perl's x.yyyzzz version format. Instead make the regular
expression more general to support version formats from older
perl-5.005_002 (5.5.2) and perl-5.11 which has other numbers
in the version line.
Jim Meyering [Sat, 28 Nov 2009 06:33:16 +0000 (07:33 +0100)]
userspec: disallow an ID that maps to (uid_t)-1 or (gid_t)-1
* lib/userspec.c (parse_with_separator): Do not accept a user ID
number of MAXUID when it evaluates to (uid_t) -1.
Likewise for group ID. Reported by Matt McCutchen in
<http://savannah.gnu.org/bugs/?28113>
Eric Blake [Sat, 28 Nov 2009 00:47:21 +0000 (17:47 -0700)]
getopt-gnu: flush out another BSD bug
POSIX requires 'echo foo > bar; m4 -Dfoo=1 bar -Dfoo=2 bar' to
output '1' then '2'. To achieve this, m4 relies on the GNU
getopt{,_long} extension of a leading '-'. However, BSD getopt
fails to honor this extension when POSIXLY_CORRECT.
Also, BSD getopt fails to reparse POSIXLY_CORRECT from the
environment even when a reset is requested (whether by
optreset=1 or by optind=0).
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Test for the bug.
* tests/test-getopt.c (main): Check POSIXLY_CORRECT first, to
flush out BSD bug.
* tests/test-getopt.h (test_getopt): End lists with NULL.
* tests/test-getopt_long.h (test_getopt_long): Likewise.
(test_getopt_long_posix): Enhance test.
* modules/getopt-posix-tests (Depends-on): Add stdbool.
* doc/glibc-functions/getopt_long.texi (getopt_long): Mention
getopt-gnu.
* doc/glibc-functions/getopt_long_only.texi (getopt_long_only):
Likewise.
Jim Meyering [Fri, 27 Nov 2009 09:19:32 +0000 (10:19 +0100)]
test-xalloc-die: avoid spurious failure due to libtool argv difference
In a libtool-enabled project, this test would fail due to a difference
in the emitted program name, e.g.,
-test-xalloc-die: memory exhausted
+/tmp/.../tests/.libs/lt-test-xalloc-die: memory exhausted
Use program to avoid that.
* modules/xalloc-die-tests (Depends-on): Add progname.
* tests/test-xalloc-die.c: Include progname.h".
(program_name): Remove decl.
(main): Call set_program_name.
* tests/test-xalloc-die.sh (compare): Remove unnecessary ${EXE}.
Jim Meyering [Thu, 26 Nov 2009 08:10:04 +0000 (09:10 +0100)]
init.sh: accommodate even those who specify bogus srcdir manually
* tests/init.sh: Normally, srcdir is guaranteed by automake and
configure-time tests to be sanitized, so that there is no need to
use "$srcdir" in Makefile rules and shell scripts. Using $srcdir
(with no double quotes) suffices. However, since tests may be
invoked manually, and since you may explicitly set srcdir to the
name of a directory containing spaces, do quote its uses here.
* tests/test-pread.sh: Likewise.
Suggested by Bruno Haible.
Jim Meyering [Thu, 26 Nov 2009 07:51:11 +0000 (08:51 +0100)]
test-pread.sh: avoid diagnostics for those who ignore SIGPIPE
* tests/test-pread.sh: Write no data into the pipe, because
test-pread actually reads none. This avoids a diagnostic,
"bash: echo: write error: Broken pipe", that arises in the unusual
event something is ignoring SIGPIPE, and might be interpreted
as some sort of failure. Reported by Bruno Haible.
Jim Meyering [Wed, 25 Nov 2009 17:01:02 +0000 (18:01 +0100)]
pread: improvement and fix
* modules/pread (Depends-on): Depend on lseek, for portability to
e.g., mingw. Suggested by Eric Blake.
* lib/pread.c (__libc_read): Define. Reported by Richard W.M. Jones.
Jim Meyering [Wed, 25 Nov 2009 15:52:47 +0000 (16:52 +0100)]
test-pread.sh: clean up
* tests/test-pread.sh: Don't refer to $builddir. Just use equivalent ".".
* modules/pread-tests (TESTS_ENVIRONMENT): Don't export builddir.
That is unnecessary, since it's always ".".
Suggestion from Eric Blake.
Eric Blake [Tue, 24 Nov 2009 17:07:57 +0000 (10:07 -0700)]
utimens: work around older Linux failure with symlinks
Some Linux kernel versions support utimensat(,0) but not
utimensat(,AT_SYMLINK_NOFOLLOW), even for non-symlinks. Had the
fallback code for regular files been reached, it would have truncated
timestamps. But since glibc lutimes just wraps utimensat, and we
didn't expect ENOSYS from lutimes, the fallback wasn't even reached.
* lib/utimens.c (lutimensat_works_really): New variable.
(fdutimens, lutimens): Use it to manage kernels that support
nanosecond times on files, but not on symlinks.
Reported by Ondřej Vašík.
* tests/test-update-copyright.sh (YEAR): Use date +%Y, rather than
perl to print the current year. Gilles Espinasse reported that
the replaced use of perl was hard-coded as /usr/bin/perl.
Eric Blake [Fri, 20 Nov 2009 13:23:42 +0000 (06:23 -0700)]
build: mention ftp redirector in release announcements
Now that http://ftpmirror.gnu.org/PACKAGE/ redirects to a nearby
mirror, we should promote its use in release announcements.
Meanwhile, mention the mirror list.
* top/maint.mk (gnu_rel_host, url_dir_list): Provide defaults for
values that used to come from cfg.mk; mention FTP redirect URL.
* build-aux/announce-gen: Mention the mirror list.
Suggested by Karl Berry.
Eric Blake [Thu, 19 Nov 2009 05:14:39 +0000 (22:14 -0700)]
nanosleep: improve port to mingw
test-nanosleep failed to link, and exposed a need for argument
validation when nanosleep is missing.
* lib/nanosleep.c (rpl_nanosleep): Reject invalid arguments.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Incorporate LIBSOCKET into
LIB_NANOSLEEP, but only when needed.
* modules/select (Link): Document LIBSOCKET.
* m4/select.m4 (gl_FUNC_SELECT): Ensure LIBSOCKET is defined early
enough.
Eric Blake [Thu, 19 Nov 2009 03:10:42 +0000 (20:10 -0700)]
nanosleep: work around cygwin bug
Cygwin 1.5.x mistakenly failed with EINVAL for a duration longer
than 49.7 days (2**32 milliseconds). Meanwhile, the existing
code for HAVE_BUG_BIG_NANOSLEEP would infloop, instead of return
failure, for invalid arguments.
* lib/nanosleep.c (rpl_nanosleep) [HAVE_BUG_BIG_NANOSLEEP]:
Fix logic bug when nanosleep fails. Work around cygwin 1.5.x
bug.
(getnow): Delete, not needed.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): No longer require
LIB_CLOCK_GETTIME.
* modules/nanosleep (Depends-on): Add intprops and verify. Drop
clock-time, gettime.
* doc/posix-functions/nanosleep.texi (nanosleep): Document the
bug.
* modules/nanosleep-tests: New test.
* tests/test-nanosleep.c: New file.
Jim Meyering [Fri, 20 Nov 2009 12:24:24 +0000 (13:24 +0100)]
maint.mk: improve sc_prohibit_magic_number_exit
* top/maint.mk (sc_prohibit_magic_number_exit): Tighten regexp
so it does not match uses like System.exit(1).
Add comments showing how to correct all offenders.
Eric Blake [Wed, 18 Nov 2009 13:59:44 +0000 (06:59 -0700)]
utimens: fix regression on Solaris
Revert commit 26c5fd742f. Solaris lacks futimens and futimes, so
futimesat is the only way to change fd timestamps. But since
FreeBSD futimesat can't change fd timestamps, we need a configure
check to avoid the crash there.
* m4/utimens.m4 (gl_UTIMENS): Check for BSD bug.
* lib/utimens.c (fdutimens): Revert 2009-11-08 change; Solaris 10
can only change fd timestamps via futimesat. Instead, use an
additional witness macro to avoid BSD bug.
Reported by Jim Meyering.
Eric Blake [Tue, 17 Nov 2009 16:24:56 +0000 (09:24 -0700)]
usleep: new module
mingw usleep(1000000) failed with EINVAL, as allowed by POSIX,
but contrary to GNU usage. Rather than implement an accurate
usleep based on select or nanosleep, both of which drag in
dependencies on external libraries, this version intentionally
takes the ceiling in seconds if usleep() is missing.
Eric Blake [Mon, 16 Nov 2009 21:35:41 +0000 (14:35 -0700)]
chown: work around OpenBSD bug
chown(name,geteuid(),-1) failed to update the change time if
name was already owned by the current effective user. Work
around it by using chmod, which does not have this bug.
Unfortunately, lchown has the same bug, but OpenBSD 4.0 lacks
lchmod and lutimes, so there is no way to affect ctime without
unlinking and recreating the symlink, which is too dangerous.
* lib/chown.c (rpl_chown): Work around the bug.
* lib/lchown.c (rpl_lchown): Attempt to do likewise.
* m4/chown.m4 (gl_FUNC_CHOWN): Test for ctime bug.
* m4/lchown.m4 (gl_FUNC_LCHOWN): Check for lchmod.
* modules/chown (Depends-on): Add stdbool.
* modules/lchown (Depends-on): Likewise.
* doc/posix-functions/chown.texi (chown): Document the bug.
* doc/posix-functions/lchown.texi (lchown): Likewise.
* tests/test-lchown.h (test_chown): Relax test.
Jim Meyering [Tue, 17 Nov 2009 07:46:29 +0000 (08:46 +0100)]
test-xalloc-die.sh: make the code agree with the commit log
* tests/test-xalloc-die.sh: Put "." at the front of $PATH, not
at the end, just in case you happen to have a test-xalloc-die
program in some other PATH directory.
Jim Meyering [Tue, 17 Nov 2009 07:42:58 +0000 (08:42 +0100)]
test-xalloc-die.sh: fix a portability bug
* tests/test-xalloc-die.sh: Do not invoke via ./test-xalloc-die.
Instead, set PATH to start with "." and invoke via "test-xalloc-die".
Otherwise, argv[0] (as often seen in diagnostics) would be too
system-dependent, sometimes with, and sometimes without the leading "./".