[PATCH 1/2] linkat: wrap to handle symlinks on OS X 10.10
These two patches remove the linkat wrapping on GNU/Linux, and add the wrapping for OSX 10.10 to fall back to emulation mode when trying to hardlink a symlink. thanks, Padraig. >From 6de3a63272b5c4904cf9c85fcf3bc5488d36db19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Fri, 31 Oct 2014 18:12:15 + Subject: [PATCH 1/2] linkat: wrap to handle symlinks on OS X 10.10 * m4/linkat.m4 (gl_FUNC_LINKAT): linkat() is available on Yosemite but not usable because it doesn't support creating hardlinks to symlinks. Therefore add a generic test for this capability and fallback to our emulation if linkat() fails with ENOTSUP. --- ChangeLog |8 doc/posix-functions/linkat.texi |5 - lib/linkat.c| 18 -- m4/linkat.m4| 26 ++ modules/linkat | 26 -- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f80f39..334a3c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-10-31 Pádraig Brady + + linkat: wrap to handle symlinks on OS X 10.10 + * m4/linkat.m4 (gl_FUNC_LINKAT): linkat() is available on Yosemite + but not usable because it doesn't support creating hardlinks + to symlinks. Therefore add a generic test for this capability + and fallback to our emulation if linkat() fails with ENOTSUP. + 2014-10-31 Paul Eggert obstack: add NEWS entry for recent incompatible changes diff --git a/doc/posix-functions/linkat.texi b/doc/posix-functions/linkat.texi index 232a50b..fadb350 100644 --- a/doc/posix-functions/linkat.texi +++ b/doc/posix-functions/linkat.texi @@ -10,10 +10,13 @@ Portability problems fixed by Gnulib: @itemize @item This function is missing on some platforms: -glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, +glibc 2.3.6, Mac OS X < 10.10, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS. But the replacement function is not safe to be used in libraries and is not multithread-safe. @item +This function fails to directly hardlink symlinks on some platforms: +Mac OS X 10.10. +@item This function fails to reject trailing slashes on non-directories on some platforms: AIX 7.1, Solaris 11 2011-11. diff --git a/lib/linkat.c b/lib/linkat.c index 6ee30fb..c01e3e3 100644 --- a/lib/linkat.c +++ b/lib/linkat.c @@ -43,7 +43,7 @@ # endif #endif -#if !HAVE_LINKAT +#if !HAVE_LINKAT || LINKAT_SYMLINK_NOTSUP /* Create a link. If FILE1 is a symlink, either create a hardlink to that symlink, or fake it by creating an identical symlink. */ @@ -195,6 +195,10 @@ solaris_optimized_link_follow (char const *file1, char const *file2) # endif +#endif /* !HAVE_LINKAT || LINKAT_SYMLINK_NOTSUP */ + +#if !HAVE_LINKAT + /* Create a link to FILE1, in the directory open on descriptor FD1, to FILE2, in the directory open on descriptor FD2. If FILE1 is a symlink, FLAG controls whether to dereference FILE1 first. If possible, do it without @@ -321,7 +325,17 @@ rpl_linkat (int fd1, char const *file1, int fd2, char const *file2, int flag) # endif if (!flag) -return linkat (fd1, file1, fd2, file2, flag); +{ + int result = linkat (fd1, file1, fd2, file2, flag); +# if LINKAT_SYMLINK_NOTSUP + /* OS X 10.10 has linkat() but it doesn't support + hardlinks to symlinks. Fallback to our emulation + in that case. */ + if (result == -1 && (errno == ENOTSUP || errno == EOPNOTSUPP)) +return at_func2 (fd1, file1, fd2, file2, link_immediate); +# endif + return result; +} /* Cache the information on whether the system call really works. */ { diff --git a/m4/linkat.m4 b/m4/linkat.m4 index 2da0e30..a2b5213 100644 --- a/m4/linkat.m4 +++ b/m4/linkat.m4 @@ -20,6 +20,27 @@ AC_DEFUN([gl_FUNC_LINKAT], if test $ac_cv_func_linkat = no; then HAVE_LINKAT=0 else +dnl OS X Yosemite has linkat() but it's not sufficient +dnl to our needs since it doesn't support creating +dnl hardlinks to symlinks. Therefore check for that +dnl capability before considering using the system version. +AC_CACHE_CHECK([whether linkat() can link symlinks], + [gl_cv_func_linkat_nofollow], + [rm -rf conftest.l1 conftest.l2 + ln -s target conftest.l1 + AC_RUN_IFELSE([AC_LANG_PROGRAM( +[[#include + #include +]], +[return linkat (AT_FDCWD, "conftest.l1", AT_FDCWD, +"conftest.l2", 0); +])], + [gl_cv_func_linkat_nofollow=yes + LINKAT_SYMLINK_NOTSUP=0], + [gl_cv_func_linkat_nofollow=no + LINKAT_SYMLINK_NOTSUP=1]) + rm -rf conftest.l1 conftest.l2]) + AC_CACHE
[PATCH] open, openat: document nonstandard FreeBSD, NetBSD O_NOFOLLOW errno
* doc/posix-functions/open.texi (open): * doc/posix-functions/openat.texi (openat): Document that these functions do not set errno to ELOOP when a symlink is opened with O_NOFOLLOW. --- ChangeLog | 8 doc/posix-functions/open.texi | 10 ++ doc/posix-functions/openat.texi | 10 ++ 3 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1f80f39..12dc392 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-11-02 Paul Eggert + + open, openat: document nonstandard FreeBSD, NetBSD O_NOFOLLOW errno + * doc/posix-functions/open.texi (open): + * doc/posix-functions/openat.texi (openat): + Document that these functions do not set errno to ELOOP when + a symlink is opened with O_NOFOLLOW. + 2014-10-31 Paul Eggert obstack: add NEWS entry for recent incompatible changes diff --git a/doc/posix-functions/open.texi b/doc/posix-functions/open.texi index dd33e82..dce5466 100644 --- a/doc/posix-functions/open.texi +++ b/doc/posix-functions/open.texi @@ -35,6 +35,16 @@ read-only descriptor for directories. Portability problems not fixed by Gnulib: @itemize @item +@code{open ("symlink", O_NOFOLLOW ...)} fails with @code{errno} set to +@code{EMLINK} instead of the POSIX-required @code{ELOOP} on some +platforms: +FreeBSD 10.1. +@item +@code{open ("symlink", O_NOFOLLOW ...)} fails with @code{errno} set to +@code{EFTYPE} instead of the POSIX-required @code{ELOOP} on some +platforms: +NetBSD 6.1. +@item On Windows, this function returns a file handle in @code{O_TEXT} mode by default; this means that it translates @code{'\n'} to CR/LF by default. Use the @code{O_BINARY} flag if you need reliable binary I/O. diff --git a/doc/posix-functions/openat.texi b/doc/posix-functions/openat.texi index 0042767..fa3eb65 100644 --- a/doc/posix-functions/openat.texi +++ b/doc/posix-functions/openat.texi @@ -25,4 +25,14 @@ Solaris 9. Portability problems not fixed by Gnulib: @itemize +@item +@code{openat (fd, "symlink", O_NOFOLLOW ...)} fails with @code{errno} +set to @code{EMLINK} instead of the POSIX-required @code{ELOOP} on +some platforms: +FreeBSD 10.1. +@item +@code{openat (fd, "symlink", O_NOFOLLOW ...)} fails with @code{errno} +set to @code{EFTYPE} instead of the POSIX-required @code{ELOOP} on +some platforms: +NetBSD 6.1. @end itemize -- 1.9.3
Re: [PATCH 0/5] obstacks again
On Fri, Oct 31, 2014 at 12:50:25PM -0700, Paul Eggert wrote: > I have a minor complaint > about obstack_blank_fast's revised documentation. It says "You can use > @code{obstack_blank_fast} with a negative size argument to make the current > object smaller." Technically, though, the argument is of type size_t so it > cannot be negative. Really, it's a fiction that the size argument of obstack_blank_fast has a type. (This is what happens when you start being pedantic in documentation. :-) A worse pedant comes along and says you aren't completely correct.) Please don't take this as a challenge to make the manual completely correct! I think we'd make it unreadable it we did. At least, I wasn't clever enough to write something that was simple yet correct.. > So, how about if we change this wording to "If @var{S} > is a positive size, you can give @code{obstack_blank_fast} a ``negated'' > (actually, large positive) size @code{-@var{S}} to shrink the current object > by @var{S} bytes." Also, it may be worth noting explicitly that this trick > does not work for object_blank. I've added: "Earlier versions of obstacks allowed you to use @code{obstack_blank} to shrink objects. This will no longer work." > Also, doesn't libc need a NEWS item for these changes? At least, gnulib > needs one; I installed the attached. Yes, thanks! I've added the bug number to the list fixed with 2.21 and stolen your wording for a NEWS item, minus the "(actually large positive)" phrase. > Don't we have similar problems with lots of other > macros and/or functions: obstack_1grow_fast, obstack_blank_fast, > obstack_int_grow, etc.? They all seem to return types that don't match the > documentation. As long as we're fixing things, this might all be done in a > separate patch. There another gnulib issue too. AC_FUNC_OBSTACK is no longer correct. The system libc may support obstacks, but not the current version. It seems to me the easiest solution is to always include obstack.o in libgnu.a. If the system libc is up to date, then obstack.o will be empty. And another small tweak: Don't use alignof.h if __IBM__ALIGNOF__ is defined (alignof.h just uses __alignof__ in that case), or when __alignof__ is defined (for oddball systems, or testing). -- Alan Modra Australia Development Lab, IBM >From 39a719f31f871143a011f368b5f74f03a9c33244 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 30 Oct 2014 15:04:07 +1030 Subject: [PATCH] obstack macro return values, and always add obstack.o Many of the obstack macros are not supposed to return a value, and obstack_next_free is supposed to return a void* not a char*. * lib/obstack.h (obstack_next_free): Return void *. (obstack_1grow_fast, obstack_blank_fast): Return void. For __GNUC__ macros: (obstack_free): Return void. (obstack_1grow, obstack_blank): Remove now unnecessary (void)0. For !__GNUC__ macros: (obstack_make_room, obstack_grow, obstack_grow0, obstack_ptr_grow_fast, obstack_int_grow_fast): Return void. * lib/obstack.c: Don't include alignof.h if __alignof__ is defined, nor when __IBM_ALIGNOF__ is defined. * modules/obstack (configure.ac): Always add obstack.o to libgnu.a. --- ChangeLog | 15 +++ lib/obstack.c | 3 ++- lib/obstack.h | 30 +- modules/obstack | 3 +-- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d6c285..5574df9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2014-11-03 Alan Modra + + obstack: macro return values, and always add obstack.o. + * lib/obstack.h (obstack_next_free): Return void *. + (obstack_1grow_fast, obstack_blank_fast): Return void. + For __GNUC__ macros: + (obstack_free): Return void. + (obstack_1grow, obstack_blank): Remove now unnecessary (void)0. + For !__GNUC__ macros: + (obstack_make_room, obstack_grow, obstack_grow0, + obstack_ptr_grow_fast, obstack_int_grow_fast): Return void. + * lib/obstack.c: Don't include alignof.h if __alignof__ is defined, + nor when __IBM_ALIGNOF__ is defined. + * modules/obstack (configure.ac): Always add obstack.o to libgnu.a. + 2014-10-30 Pádraig Brady mountlist: don't use libmount to decide on dummy/remote diff --git a/lib/obstack.c b/lib/obstack.c index ba7dff3..e1707b9 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -48,7 +48,8 @@ #endif #ifndef _OBSTACK_ELIDE_CODE -# if !defined _LIBC && !defined __GNUC__ +# if (!defined _LIBC && !defined __GNUC__ && !defined __IBM__ALIGNOF__ \ + && !defined __alignof__) # include # define __alignof__(type) alignof_type (type) # endif diff --git a/lib/obstack.h b/lib/obstack.h index ba4de1d..79edffb 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -219,7 +219,7 @@ extern int obstack_exit_failure; /* Pointer to next byte not yet allocated in current chunk. */ -#define obstack_next_free(h)((h)->next_free) +#define obstack_next_free(h) ((void *) (h)->next_free) /* Mask specifying low bits that should be cl