Eric Blake [Thu, 15 Oct 2009 18:04:57 +0000 (12:04 -0600)]
utimens: let lutimens work on non-symlinks
Coreutils new 'touch -h' is easier to write if we guarantee POSIX
semantics of utimensat(fd,"file",NULL,AT_SYMLINK_NOFOLLOW), rather
than blindly failing with ENOSYS even on non-symlinks.
* lib/utimens.c (lutimens): Fall back to utimens rather than
failing with ENOSYS, when file is not a symlink.
(utimens): Reduce redirection.
* tests/test-lutimens.h (test_lutimens): Update test to cover
non-symlinks.
* tests/test-utimens.h (test_utimens): Update test to cover
symlinks.
* tests/test-utimens.c (main): Update caller.
Eric Blake [Mon, 12 Oct 2009 16:42:35 +0000 (10:42 -0600)]
test-stat-time, test-utimens: improve portability
ext4 on an alpha system has a quantization of about 10 ms but
a resolution of 1ns; utimecmp does not know about quantization,
so tests were failing when comparing timestamps that fall
within the same quantization window. Add strategic usleeps
throughout to minimize this issue, whether or not we later
improve utimecmp to account for quantization.
Windows (and hence cygwin) is documented as having a default
clock quantization of 15.25 milliseconds (although it can be
reduced to 1 millisecond); file timestamps are quantized to this
boundary even though more accurate timing can be obtained.
However, this means that 15 milliseconds is too short for any
test that wants to guarantee crossing a file timestamp boundary.
Cygwin, however, still has bugs where clock_gettime can lag
behind file timestamps, which is not fixed by this patch.
Solaris 9 with NFS exposed the same problem for futimes that was
previously fixed for utimes on Solaris 8, where futimens(f,NULL)
uses a different time source than futimes(,{,UTIME_NOW}).
* tests/test-stat-time.c (nap): Lengthen delay to 20ms, for
ext4 on alpha, and for cygwin.
* tests/test-utimens-common.h: New file.
(nap): Factor delays into single function.
* tests/test-lutimens.h (test_lutimens): Use new header.
* tests/test-futimens.h (test_futimens): Likewise.
* tests/test-utimens.h (test_utimens): Likewise. Also, force NFS
timestamps to occur from same machine, as was done previously for
test_utimens.
* modules/utimens-tests (Files): Ship new file.
* modules/futimens-tests (Files): Likewise.
Reported in part by Jim Meyering.
Jim Meyering [Thu, 15 Oct 2009 19:04:51 +0000 (21:04 +0200)]
don't let environment settings perturb build
Setting the envvars, LIB_CLOCK_GETTIME, LIB_EACCESS or LIB_NANOSLEEP
could cause a configure-time and/or build-time malfunction.
Typically, a configure-time function-in-library test is performed
via code like this:
However, in each of the files affected by this change, the LIB_VAR=
initialization was omitted. Thus, when set in the environment, its
value would propagate into generated Makefiles when FUNC is not found
in LIB_NAME.
* m4/clock_time.m4 (gl_CLOCK_TIME): Initialize AC_SUBST'd var.
* m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Likewise.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Likewise.
Eric Blake [Tue, 13 Oct 2009 15:16:16 +0000 (09:16 -0600)]
test-stat-time: port to mingw
Newer mingw has usleep, but it rejects arguments over 1000000
without sleeping. And since stat has no visibility into
sub-second resolutions, it meant all the timestamps ended up
identical. Fixed by restoring the 8 seconds of sleep, as
well as working around the documented unlink issue.
* tests/test-stat-time.c (force_unlink): Return a value.
(test_ctime) [W32]: Fix compilation error.
(nap): Don't call usleep with too large an argument. Use
force_unlink.
* doc/pastposix-functions/usleep.texi (usleep): Document the
portability issue.
Jim Meyering [Tue, 13 Oct 2009 07:15:52 +0000 (09:15 +0200)]
use AC_CHECK_FUNCS_ONCE, not AC_CHECK_FUNCS in modules/*
* modules/pipe-filter-gi: Use AC_CHECK_FUNCS_ONCE, not AC_CHECK_FUNCS.
* modules/pipe-filter-ii: Likewise.
* modules/sys_socket-tests: Likewise.
* modules/tsearch-tests: Likewise.
* Makefile (sc_prefer_ac_check_funcs_once): New rule.
(check): Depend on it.
Eric Blake [Mon, 12 Oct 2009 16:42:35 +0000 (10:42 -0600)]
utimens-tests: port to NFS file systems
Testing on Solaris 8 with NFS: creat() and utimens(,NULL) seem to
set timestamps according to the current time on the server, while
utimens(,{,UTIME_NOW}) sets timestamps according to the current
time on the client. If two machines are not perfectly
synchronized in time, then this makes time appear to move
backwards. Avoid spurious test failures caused by a mtime
comparison across machines, by instead doing 2 mtime comparisons,
each known to be from timestamps tied to a single machine.
* tests/test-utimens.h (test_utimens): Add a utimens call prior to
grabbing stat buffer.
Eric Blake [Mon, 12 Oct 2009 16:37:48 +0000 (10:37 -0600)]
stat-time-tests: minor cleanups
* modules/stat-time-tests (configure.ac): Use AC_CHECK_FUNCS_ONCE.
* tests/test-stat-time.c (nap): Separate assignment from call.
Suggested by Paolo Bonzini and Bruno Haible.
Eric Blake [Mon, 12 Oct 2009 16:36:33 +0000 (10:36 -0600)]
sys_stat: guarantee struct timespec
* lib/sys_stat.in.h (includes): Always include <time.h>
* modules/sys_stat (Depends-on): Add time.
* tests/test-sys_stat.c: Guarantee struct timespec, as well as
mode_t permission values.
* doc/posix-headers/sys_stat.texi (sys/stat.h): Document how to
get at subsecond timestamps.
Eric Blake [Thu, 8 Oct 2009 12:40:08 +0000 (06:40 -0600)]
utimens: introduce fdutimens
at-func.c wants the file name argument first. This also paves the
way to add fdutimensat(dfd,name,fd,times,flag).
* lib/utimens.h (fdutimens): New prototype.
* lib/utimens.c (gl_futimens): Move guts...
(fdutimens): ...to new interface.
* tests/test-utimens.c (do_fdutimens): Use it.
Eric Blake [Wed, 7 Oct 2009 22:05:34 +0000 (16:05 -0600)]
utimens: add UTIME_NOW and UTIME_OMIT support
These flags make it possible to implement futimens and utimensat;
they also make touch(1) more efficient, by avoiding stat or
gettime if native utimensat works.
* lib/utimens.c (validate_timespec, update_timespec): New helper
functions.
(gl_futimens, lutimens): Use them.
* modules/utimens (Depends-on): Add gettime, lstat, stat-time,
stdbool, sys_stat.
(Link): Mention resulting library dependency.
* modules/utimecmp (Link): Likewise.
* modules/utimens-tests (Depends-on): Drop stat-time, stdbool.
(Makefile.am): Pick up library dependency.
* lib/sys_stat.in.h (UTIME_NOW, UTIME_OMIT): Guarantee a
definition.
* tests/test-sys_stat.c: Test the definitions.
* doc/posix-headers/sys_stat.texi (sys/stat.h): Document this.
* NEWS: Document library dependency.
Eric Blake [Thu, 8 Oct 2009 04:06:49 +0000 (22:06 -0600)]
utimecmp: support symlink timestamps
Update this module to reflect POSIX 2008:
With pathconf, we can avoid calling utimens.
With utimensat, the system resolution can be 1.
With lutimens, we can determine resolution on symlinks.
* lib/utimecmp.c (utimecmp): Use new interface. Skip effort of
hashing when possible. Use pathconf when available.
(SYSCALL_RESOLUTION): Recognize tighter resolution.
* modules/utimecmp (Depends-on): Add lstat.
Eric Blake [Wed, 7 Oct 2009 19:36:45 +0000 (13:36 -0600)]
utimens: add lutimens interface
Wraps utimensat(,AT_SYMLINK_NOFOLLOW) or lutimes, when supported;
otherwise fail with ENOSYS. Allows coreutils' copy.c to preserve
symlink timestamps on more systems. Note that cygwin's lstat
changes atime of symlinks, but mtime can reliably be set.
* lib/utimens.c (lutimens): New function.
* m4/utimens.m4 (gl_UTIMENS): Check for lutimes.
* lib/utimens.h (lutimens): Declare new interface.
* tests/test-utimens.c (main): Enhance test.
* tests/test-lutimens.h (test_lutimens): New file.
* modules/utimens-tests (Files): Distribute it.
(Depends-on): Add symlink.
(configure.ac): Check for usleep.
Eric Blake [Tue, 6 Oct 2009 18:23:32 +0000 (12:23 -0600)]
utimens: validate futimens usage
Using gl_futimens(fd,NULL,times) as an implementation for futimens
won't work unless we reliably detect EBADF for out-of-range fd.
Also catches a Linux bug with futimens(AT_FDCWD,NULL) changing ".".
mingw <utime.h> has a bug where utime's second argument is not const.
* lib/utimens.c (gl_futimens): Require valid fd up front, using
fewer syscalls on failure later on. Avoid compiler warning on
mingw.
* modules/utimens (Depends-on): Add dup2.
Eric Blake [Sat, 10 Oct 2009 14:04:41 +0000 (08:04 -0600)]
test-stat-time: avoid more spurious failures
On xfs, although timestamps can have a full nanosecond resolution,
successive file actions appear to be quantized to approximately
10 millisecond windows. Running with just 1 ms delays could
cause two actions to fall in the same window, leading to sporadic
failures on a fast enough machine. Slow down to prevent this.
On ext2, timestamps only have 1 second resolution, but if the
first timestamp was made at 1.95 and the second at 2.10, then
the two files appear 1 second apart, and the shorter delay was
used, causing spurious failures. Require that the observable
difference lie within the same second, using a second try if
necessary, to prevent this.
* tests/test-stat-time.c (nap): Wait for 15ms rather than 2ms, for
xfs; and avoid race if the two timestamps cross quantization edge.
Eric Blake [Sat, 10 Oct 2009 03:09:38 +0000 (21:09 -0600)]
test-stat-time: port to buggy NFS clients
On darwin, the NFS client reports mtime with st_sec==INT_MAX and
st_nsec monotonically increasing per transaction until the next
sync(); but sync() is expensive, so it is easier to just skip
this part of the test if mtime is nowhere near ctime.
* tests/test-stat-time.c (main) [W32]: Reduce ifdefs.
(test_ctime): Also skip test if mtime and ctime are skewed.
Eric Blake [Fri, 9 Oct 2009 17:55:46 +0000 (11:55 -0600)]
test-stat-time: speed up execution
Eight seconds was painfully long.
* tests/test-stat-time.c (test_ctime) [!W32]: Avoid compiler
warning on mingw.
(nap): New helper function.
(prepare_test): Use it to reduce sleep time.
(test_mtime, test_ctime, test_birthtime): Allow for subsecond
execution.
* modules/stat-time-tests (configure.ac): Check for usleep.
Jim Meyering [Wed, 7 Oct 2009 17:00:42 +0000 (19:00 +0200)]
selinux-h: always use getfilecon wrappers
* lib/getfilecon.c: New file.
* lib/se-selinux.in.h: Use a better inclusion guard symbol name.
[HAVE_SELINUX_SELINUX_H]: Include-next <selinux/selinux.h>.
[!HAVE_SELINUX_SELINUX_H]: Use better parameter names.
(fgetfilecon): Provide a stub.
* m4/selinux-selinux-h.m4 (gl_HEADERS_SELINUX_SELINUX_H): Don't
AC_SUBST SELINUX_SELINUX_H, since now we're generating that
file unconditionally.
When <selinux/selinux.h> is found, arrange to use wrappers.
* modules/selinux-h (Files): Add getfilecon.c.
(Makefile.am): Substitute include-next-related bits
into the now-always-generated selinux/selinux.h file.
* doc/glibc-functions/getfilecon.texi: New file.
* doc/glibc-functions/lgetfilecon.texi: New file.
* doc/glibc-functions/fgetfilecon.texi: New file.
* doc/glibc-functions/getfilecon-desc.texi: New file.
* doc/gnulib.texi (Glibc selinux/selinux.h): New section, by
which to pull in the new files.
* MODULES.html.sh (Misc): Add selinux-h.
Eric Blake [Thu, 8 Oct 2009 16:09:05 +0000 (10:09 -0600)]
areadlink: use SIZE_MAX consistently
* modules/areadlink (Depends-on): Add stdint.
* modules/areadlink-with-size (Depends-on): Likewise.
* lib/areadlink-with-size.c (includes): Drop stdio, since stdlib
gives NULL; drop sys/types, since unistd gives size_t; and add
stdint for SIZE_MAX.
(SIZE_MAX): Rely on headers.
* lib/areadlinkat-with-size.c (includes): Drop stdio, sys/types,
and add stdint.
* lib/areadlink.c (includes): Drop sys/types, and add stdint.
(SIZE_MAX): Likewise.
(INITIAL_BUF_SIZE): Turn into enum.
* lib/areadlinkat.c (INITIAL_BUF_SIZE): Likewise.
Eric Blake [Wed, 7 Oct 2009 16:52:15 +0000 (10:52 -0600)]
areadlinkat-with-size: new module
* modules/areadlinkat-with-size: New module.
* lib/areadlinkat-with-size.c (areadlinkat_with_size): New file.
* lib/areadlink.h (areadlinkat): Declare it.
* MODULES.html.sh (File system functions): Mention it.
* modules/areadlinkat-with-size-tests: New test.
* tests/test-areadlinkat-with-size.c: New file.
Eric Blake [Wed, 7 Oct 2009 16:39:29 +0000 (10:39 -0600)]
xreadlinkat: new module
* modules/xreadlinkat: New module.
* lib/xreadlinkat.c (xreadlinkat): New file.
* lib/xreadlink.h (xreadlinkat): Declare it.
* MODULES.html.sh (File system functions): Mention it.
Eric Blake [Wed, 7 Oct 2009 16:15:33 +0000 (10:15 -0600)]
areadlinkat: new module
* lib/at-func.c (FUNC_FAIL): New define.
(AT_FUNC_NAME, VALIDATE_FLAG): Use it rather than raw -1.
* modules/areadlinkat: New module.
* lib/linkat.c (areadlinkat): Move...
* lib/areadlinkat.c (areadlinkat): ...to new file.
* lib/areadlink.h (areadlinkat): Declare it.
* modules/linkat (Depends-on): Add areadlinkat.
* MODULES.html.sh (File system functions): Mention it.
* modules/areadlinkat-tests: New test.
* tests/test-areadlinkat.c: New file.
Eric Blake [Tue, 6 Oct 2009 21:43:12 +0000 (15:43 -0600)]
mkdir, mkdirat: add tests
This test exposes failures on cygwin 1.5 and in our mkdirat emulation.
* modules/mkdir-tests: New test.
* tests/test-mkdir.h: New file.
* tests/test-mkdir.c: Likewise.
* tests/test-mkdirat.c: Likewise.
* modules/openat-tests (Files): Add new files.
(Makefile.am): Run new test.
Eric Blake [Tue, 6 Oct 2009 12:58:08 +0000 (06:58 -0600)]
fdopendir: fix GNU/Hurd bug
fdopendir(open("file",O_RDONLY)) mistakenly succeeded, with
subsequent readdir() failing with ENOTDIR.
* m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Check for Hurd bug in
allowing non-directory fds.
* lib/fdopendir.c (rpl_fdopendir): Work around it.
* m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): New witness.
* modules/dirent (Makefile.am): Substitute it.
* lib/dirent.in.h (fdopendir): Declare replacement.
* doc/posix-functions/fdopendir.texi (fdopendir): Document this.
* tests/test-fdopendir.c (main): Test something other than
/dev/null, since on Hurd that behaves like a directory.
Eric Blake [Tue, 6 Oct 2009 20:29:13 +0000 (14:29 -0600)]
getopt-gnu: add another test
Ensure that POSIXLY_CORRECT does not interfere with optional argument
behavior; older BSD implementations botched this.
* tests/test-getopt_long.h (test_getopt_long_posix): New test, to
guarantee behavior relied on by m4.
* tests/test-getopt.c (main): Use it.
* modules/getopt-posix-tests (Depends-on): Add setenv.
See http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html.
Eric Blake [Wed, 7 Oct 2009 02:44:13 +0000 (20:44 -0600)]
getopt: fix compilation on darwin
* lib/getopt.in.h (includes): Leave breadcrumbs during system
include.
* lib/unistd.in.h (getopt): Use them to avoid recursive include.
Reported by Ludovic Courtès.
Eric Blake [Mon, 5 Oct 2009 23:17:34 +0000 (17:17 -0600)]
quotearg: port test to systems with C.UTF-8 locale
* tests/test-quotearg.c (struct result_strings): Add another
member, differentiating between C.ASCII and C.UTF-8 handling.
(compare_strings): Add parameter.
(main): Adjust all callers.
Eric Blake [Fri, 2 Oct 2009 18:05:02 +0000 (12:05 -0600)]
rename, fchdir: don't ignore chdir failure
Although we just checked that chdir(cwd) worked, there is a
race where it could disappear while we are temporarily away.
If that happens, forcefully give up rather than proceeding
in the wrong directory.
* lib/fchdir.c (get_name): Abort on unexpected chdir failure.
* lib/rename.c (rpl_rename) [W32]: Likewise.
(rpl_rename) [RENAME_DEST_EXISTS_BUG]: Avoid one case of losing
an empty destination directory if source cannot be renamed,
although there is still possibility for failure.
* doc/posix-functions/rename.texi (rename): Document the race.
Reported by Jim Meyering.
Eric Blake [Thu, 1 Oct 2009 22:46:08 +0000 (16:46 -0600)]
rename: fix mingw bugs
Copy various workarounds from cygwin 1.5: rename("dir/.","name"),
rename("dir","file"), rename("dir1","dir2"). Amazingly,
even though mingw stat() has no way to identify hard linked
files, and even though rename("hard1","hard2") destroys the
hard link, the lower-level MoveFileEx does the right thing!
Eric Blake [Thu, 1 Oct 2009 17:57:47 +0000 (11:57 -0600)]
rename: fix another cygwin 1.5 bug
Cygwin 1.5 sometimes, but not always, failed on rename("dir1","dir2")
when "dir2" exists. Beef up the m4 tests to more reliably
detect at least one of cygwin's bugs, in spite of not knowing
why the rename only failed sporadically (thankfully, cygwin 1.7
does not have the bug). Meanwhile, although NetBSD needs to
share the hard link workarounds, it does not need the trailing
dot and directory workarounds, so split the m4 test into two
separate feature checks.
* m4/rename.m4 (gl_FUNC_RENAME): Split cygwin bugs into two
checks.
* lib/rename.c (rpl_rename): Don't penalize NetBSD with
unnecessary cygwin workarounds. Also work around bug with moving
full directory onto an empty one.
* modules/rename (Depends-on): Add canonicalize-lgpl, rmdir.
Eric Blake [Sat, 26 Sep 2009 21:18:13 +0000 (15:18 -0600)]
rename-dest-slash: merge into rename module
Tested that NetBSD workaround still passes unit test.
* modules/rename-dest-slash (Status): Mark obsolete.
(Depends-on): Add rename.
(Files): Let rename do it all.
* m4/rename.m4 (gl_FUNC_RENAME): Also test for NetBSD bugs,
subsuming the test from gl_FUNC_RENAME_TRAILING_DEST_SLASH...
* m4/rename-dest-slash.m4: ...so this file can be deleted.
* lib/rename-dest-slash.c (rpl_rename_dest_slash): Delete.
* lib/rename.c (rpl_rename): Update comments.
Eric Blake [Tue, 29 Sep 2009 22:42:59 +0000 (16:42 -0600)]
rename: fix cygwin 1.5.x bugs
On cygwin 1.5.x, rename("dir","file") mistakenly succeeded.
rename("hard1","hard2") mistakenly reduced the hard link count,
such that "hard1" disappears once "hard2" is unlinked.
* m4/rename.m4 (gl_FUNC_RENAME): Detect cygwin bugs.
* lib/rename.c (rpl_rename): Work around them.
* modules/rename (Depends-on): Add same-inode.
Eric Blake [Thu, 1 Oct 2009 03:57:58 +0000 (21:57 -0600)]
rename: fix Solaris 10 bug
rename("file","name/") mistakenly succeeded. But since Solaris 10
already obeys POSIX behavior on rename("link/","name"), we avoid
blindly forcing GNU behavior of rejecting symlinks with trailing slash.
* m4/rename.m4 (gl_FUNC_RENAME): Detect Solaris bug.
* lib/rename.c (rpl_rename): Don't cripple POSIX behavior if this
was the only bug.
Eric Blake [Sat, 26 Sep 2009 23:22:15 +0000 (17:22 -0600)]
rename-tests: new test, exposes several platform bugs
This test passes on GNU/Linux, OpenBSD, and Cygwin 1.7.
Elsewhere, this test fails because of at least these bugs:
Solaris 10, cygwin 1.5.x, and mingw all mistakenly succeed on
rename("file","other/"). Solaris 9 and the gnulib replacement
for SunOS 4.1 mistakenly succeed on rename("file/","other").
Cygwin 1.5.x and mingw mistakenly succeed on rename("dir","d/.").
Cygwin 1.5.x and NetBSD 1.6 (even with the gnulib replacement)
mistakenly reduce the link count on rename("hard1","hard2").
* modules/rename-tests: New file.
* tests/test-rename.h: Likewise.
* tests/test-rename.c: Likewise.
* doc/posix-functions/rename.texi (rename): Improve documentation,
including bugs that will eventually be fixed in gnulib.
Jim Meyering [Fri, 2 Oct 2009 09:03:48 +0000 (11:03 +0200)]
gnu-web-doc-update: New module.
Use this script to automatically update the on-line web documentation
for your GNU project at http://www.gnu.org/software/$pkg/manual/
* modules/gnu-web-doc-update: New file.
* build-aux/gnu-web-doc-update: New script, from coreutils.
* MODULES.html.sh (Support for maintaining and releasing projects):
Add gnu-web-doc-update.
Eric Blake [Tue, 29 Sep 2009 17:40:49 +0000 (11:40 -0600)]
tests: tighten link, rmdir, and remove tests
Catch cygwin bug where rmdir("a/./") failed but rmdir("a/.//")
succeeded. Be kinder if a Solaris root user runs the test.
* tests/test-link.h (includes): No need to use <config.h> here.
Clean up if directory hard link was created, otherwise test for
trailing '.'.
* tests/test-linkat.c (main): Simplify.
* tests/test-remove.c (main): Enhance test for trailing '.'.
* tests/test-rmdir.h (test_rmdir_func): Likewise.
Jim Meyering [Thu, 1 Oct 2009 08:09:30 +0000 (10:09 +0200)]
maint.mk: requiring "make major" was annoying, for a "minor" release.
What is intended is "stable", to contrast with alpha and beta,
so require "make stable", not "make major".
* build-aux/announce-gen (%valid_release_types): s/major/stable/.
(get_tool_versions): Likewise.
* top/maint.mk (ALL_RECURSIVE_TARGETS): s/major/stable/