[Top][All Lists]

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

Re: linkat, LINK_FOLLOWS_SYMLINKS, and Solaris

From: Paul Eggert
Subject: Re: linkat, LINK_FOLLOWS_SYMLINKS, and Solaris
Date: Sun, 26 Dec 2010 11:15:47 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20101208 Thunderbird/3.1.7

[Adding libtool to the CC: list, since Bob indicates there are
libtool and autoconf implications as well.  The thread starts at

On 12/26/2010 09:51 AM, Bruno Haible wrote:

> 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.

Given the other problems that ensue on Solaris when one compiles and
links to different standards, the simplest answer may be just "don't
do that".  It's not just the __xpg4 and __xpg6 stuff; it's also the
_lib_version stuff: scanf behaves differently depending on which
flavor of the -X option one passes to cc.  It's quite a mess.

If (despite the above) we do want to support compiling an application
with cc -xwhatever or cc -Xwhatever, while linking to a library built
in the default mode, the proposed change would appear to place a
significant performance penalty for the (presumably more common) case
of compiling and linking in the default mode.  I would suggest something
like the following patch instead, with a similar patch for link_follow,
and with the appropriate m4 magic to make LINK_FOLLOWS_SYMLINKS a
runtime test (__xpg4) on hosts like Solaris that have the __xpg4 variable.

(Overall, though, it may be better not to poke a stick at this particular
beehive.  :-)

diff --git a/lib/linkat.c b/lib/linkat.c
index 73b1e3e..9b3550a 100644
--- a/lib/linkat.c
+++ b/lib/linkat.c
@@ -48,13 +48,17 @@
 /* Create a link.  If FILE1 is a symlink, either create a hardlink to
    that symlink, or fake it by creating an identical symlink.  */
-#  define link_immediate link
-# else
 static int
 link_immediate (char const *file1, char const *file2)
-  char *target = areadlink (file1);
+  char *target = NULL;
+  int target_errno = 0;
+    {
+      target = areadlink (file1);
+      target_errno = errno;
+    }
   if (target)
       /* A symlink cannot be modified in-place.  Therefore, creating
@@ -89,11 +93,10 @@ link_immediate (char const *file1, char const *file2)
       free (target);
       free (dir);
-  if (errno == ENOMEM)
+  if (target_errno == ENOMEM)
     return -1;
   return link (file1, file2);
-# endif /* LINK_FOLLOWS_SYMLINKS == 0 */
 /* Create a link.  If FILE1 is a symlink, create a hardlink to the
    canonicalized file.  */

reply via email to

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