From be2ab165f76c0bd0d37bcb7a292a4427827d3213 Mon Sep 17 00:00:00 2001 From: lotherk Date: Fri, 13 Nov 2026 21:46:37 +0000 Subject: [PATCH] make install: rename, never copy over a mapped file cp truncates the inode a running splinter has mapped, so the pages under a live gateway change and it jumps into garbage. That is what killed the daemon while make install ran (SIGSEGV at 0xb176). Link to a temp name and rename; the old inode stays mapped for whatever is already running. Co-Authored-By: Claude Opus 5.5 --- Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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: