[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

linkat, LINK_FOLLOWS_SYMLINKS, and Solaris

From: Bruno Haible
Subject: linkat, LINK_FOLLOWS_SYMLINKS, and Solaris
Date: Sun, 26 Dec 2010 18:51:40 +0100
User-agent: KMail/1.9.9

Hi Eric,

In the linkat implementation (lib/linkat.c), there is the assumption that
the value of LINK_FOLLOWS_SYMLINKS depends only on the current machine
and platform. But this is not the case: On Solaris 10 systems (which
don't have linkat() in libc), the behaviour of the link() function
depends on whether some part of the program (the executable or one of
its shared libraries) has included the /usr/lib/values-xpg6.o or
/usr/lib/values-xpg4.o file.
(See <http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html>
for details.)

Witness: the test program from m4/link-follow.m4 returns with exit code 0
when compiled with "cc" or "gcc", but with exit code 1 when it is linked
with /usr/lib/values-xpg6.o.

$ echo > conftest.file
$ gcc foo.c
$ rm conftest.sym conftest.hard ; ./a.out ; echo $?
$ gcc foo.c /usr/lib/values-xpg4.o 
$ rm conftest.sym conftest.hard ; ./a.out ; echo $?
$ gcc foo.c /usr/lib/values-xpg6.o 
$ rm conftest.sym conftest.hard ; ./a.out ; echo $?

So, when libposix becomes reality, it may be compiled with "gcc", thus
with a setting of
But when it gets linked to a program that was compiled with "c99" or
"cc -xc99=all", then the link() function _will_ follow symlinks,
thus the link_immediate function will not perform as expected.

Here's a suggested fix:

2010-12-26  Bruno Haible  <address@hidden>

        linkat: Make implementation robust against system behaviour variations.
        * lib/linkat.c (link_immediate): On Solaris, always take the slow but
        safe route.

--- lib/linkat.c.orig   Sun Dec 26 17:14:14 2010
+++ lib/linkat.c        Sun Dec 26 17:13:49 2010
@@ -48,7 +48,10 @@
 /* Create a link.  If FILE1 is a symlink, either create a hardlink to
    that symlink, or fake it by creating an identical symlink.  */
+/* On Solaris, link() doesn't follow symlinks by default, but does so as soon
+   as a library or executable takes part in the program that has been compiled
+   with "c99" or "cc -xc99=all".  */
+# if LINK_FOLLOWS_SYMLINKS == 0 && !defined __sun
 #  define link_immediate link
 # else
 static int

reply via email to

[Prev in Thread] Current Thread [Next in Thread]