diff --git a/Makefile b/Makefile index baec548..e868e22 100644 --- a/Makefile +++ b/Makefile @@ -270,14 +270,26 @@ check: $(LIB) $(BIN) $(PLUGIN) $(TESTS) # The installed binary finds its own library through an rpath relative to itself # ($ORIGIN), so 'make install PREFIX=$HOME/.local' produces a program that runs # without a wrapper, without LD_LIBRARY_PATH and without an environment file. +# Install by rename, never in place. A running splinter has these files +# mapped: cp truncates the old inode and writes into pages the process is +# executing, which killed a gateway that was up while make install ran +# (SIGSEGV at a nonsense address). A rename swaps the directory entry and +# leaves the mapped inode alone. install: all mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib \ $(DESTDIR)$(PREFIX)/lib/splinter/plugins $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \ - -o $(DESTDIR)$(PREFIX)/bin/splinter $(BINOBJ) -L. -lsplinter \ + -o $(DESTDIR)$(PREFIX)/bin/.splinter.new $(BINOBJ) -L. -lsplinter \ $(CURSES_A) $(LIBS) - cp $(LIB) $(DESTDIR)$(PREFIX)/lib/ - cp $(PLUGIN) $(DESTDIR)$(PREFIX)/lib/splinter/plugins/ + mv -f $(DESTDIR)$(PREFIX)/bin/.splinter.new \ + $(DESTDIR)$(PREFIX)/bin/splinter + cp $(LIB) $(DESTDIR)$(PREFIX)/lib/.$(LIB).new + mv -f $(DESTDIR)$(PREFIX)/lib/.$(LIB).new $(DESTDIR)$(PREFIX)/lib/$(LIB) + for p in $(PLUGIN); do \ + cp "$$p" "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" && \ + mv -f "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" \ + "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/$${p##*/}" || exit 1; \ + done @echo "installed $(DESTDIR)$(PREFIX)/bin/splinter" clean: