OSDN Git Service

fix atomicity and other issues installing dynamic linker symlink
authorRich Felker <dalias@aerifal.cx>
Fri, 16 Aug 2013 21:51:38 +0000 (17:51 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 16 Aug 2013 21:51:38 +0000 (17:51 -0400)
ln -sf is non-atomic; it unlinks the destination first. instead, make
a temporary link and rename it into place.

this commit also fixes some of the dependency tracking behavior for
the link. depending on the directory it's to be installed in is not
reasonable; it causes a new link to be attempted if the library
directory has been modified, but does not attempt to make a new link
just because libc has been updated. instead, depend on the target to
be linked to. this will ensure that, if prefix has changed but
syslibdir has not, the link will be updated to point to the new
prefix.

Makefile

index 33c2de1..7e634da 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -155,11 +155,9 @@ $(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
 $(DESTDIR)$(includedir)/%: include/%
        install -D -m 644 $< $@
 
-$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
-       ln -sf $(libdir)/libc.so $@ || true
-
-$(DESTDIR)$(syslibdir):
-       install -d -m 755 $(DESTDIR)$(syslibdir)
+$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
+       test -d $(DESTDIR)$(syslibdir) || install -d -m 755 $(DESTDIR)$(syslibdir) || true
+       { ln -sf $(libdir)/libc.so $@.tmp.$$$$ && mv -f $@.tmp.$$$$ $@ ; } || true
 
 install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)