Source-Changes-D archive

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

Re: CVS commit: src/share/mk

On Wed, 22 Jan 2014, Christos Zoulas wrote:
On Jan 22,  7:29am, (Matt Thomas) wrote:
-- Subject: Re: CVS commit: src/share/mk

| I always wondered why we don't use ln -sf=20
| and avoid the race.

That does not work because if the destnation is a directory it will
try to link in the destination directory... (I tried). This is why
I suggested that it needs to be done differently.

In the common case, all this linking is happening in an OBJDIR
which either started off empty, or started off with the correct
symlinks.  It might be possible to detect this common case and
arrange for it to be race-free.

I don't think "ln -sf" is so bad. The first time, you get the desired symlink:

        /dirname/linkname -> destination

then the second time, if you lose the race, you get a useless and mostly harmless extra link:

        /dirname/destination/destination -> destination

My tests suggest that the third time, and every other time you run "ln -sf destination /dirname/linkname", nothing really changes. /dirname/destination/destination might be deleted and re-created, but (at least on NetBSD and Linux) nothing worse happens.

If the extra link is offensive, then just delete it, making the
entire sequence like this:

    # remove old symlink
    rm -f /dirname/linkname
    # create desired new symlink,
    # or create bogus extra link (if we lose the race)
    ln -sf destination /dirname/linkname
    # remove bogus extra link (if it exists)
    rm -f /dirname/destination/destination

"ln -sfh" is not portable, so we can't use that.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index