Re: link(2) creates hard link to symlink in some cases

Mark Hemment (markhe@nextd.demon.co.uk)
Mon, 23 Dec 1996 20:49:15 +0000 (GMT)


Hi,

On Sun, 22 Dec 1996, Bruce Perens wrote:
> Under 2.0.27, link(2) creates a hard link to a symlink,
> but only if the target of the symlink exists. This can't
> be the intended behavior.

It may have been the intended behaviour, but it's certainly the wrong
behaviour.
I test on both SCO's OpenServer, and UnixWare 2.1. Both followed the
symlink for link(2). Not sure what a BSD derived system does...

As X/Open Issue 4, Version 2, now covers symlinks, I checked in there.
While they didn't describe the 'following' behaviour of link(2), the
ELOOP errno is doc'ed as a Unix extension - suggesting symlinks are
followed.
Below is a patch, against 2.1.16 but should apply to 2.0.x kernels, to
change the behaviour. The only question is; "Does this change break any
applications?".

--- namei.c.00 Mon Dec 23 19:47:39 1996
+++ namei.c Mon Dec 23 19:47:41 1996
@@ -816,7 +816,7 @@
char * to;
struct inode * oldinode;

- error = lnamei(oldname, &oldinode);
+ error = namei(oldname, &oldinode);
if (error)
return error;
error = getname(newname,&to);