From b062ba20d4420ecb766ffdff345f2044e311adea Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 28 Aug 2024 09:24:15 +0930 Subject: [PATCH] lightningd: fix up installs in subdirectories. Commit a1fdeee76b "Makefile: clean up install path handling." broke the ability to configure with one path and then run in a different path. Turns out people actually do this! So, we have to use relative paths, compared to our existing binary. Fixes: https://github.com/ElementsProject/lightning/issues/7595 Signed-off-by: Rusty Russell --- Makefile | 4 ++-- lightningd/lightningd.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 43055ffa0e1d..d4551cf79b70 100644 --- a/Makefile +++ b/Makefile @@ -252,7 +252,7 @@ CPATH := /usr/local/include LIBRARY_PATH := /usr/local/lib endif -CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 +CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS) # If CFLAGS is already set in the environment of make (to whatever value, it @@ -886,7 +886,7 @@ uninstall: installcheck: all-programs @rm -rf testinstall || true $(MAKE) DESTDIR=$$(pwd)/testinstall install - DEV_LIGHTNINGD_DESTDIR_PREFIX=$$(pwd)/testinstall/ testinstall$(bindir)/lightningd --test-daemons-only --lightning-dir=testinstall + testinstall$(bindir)/lightningd --test-daemons-only --lightning-dir=testinstall $(MAKE) DESTDIR=$$(pwd)/testinstall uninstall @if test `find testinstall '!' -type d | wc -l` -ne 0; then \ echo 'make uninstall left some files in testinstall directory!'; \ diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 8ed03a250033..93f343ad7464 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -534,7 +534,7 @@ static const char *find_my_directory(const tal_t *ctx, const char *argv0) static void find_subdaemons_and_plugins(struct lightningd *ld, const char *argv0) { const char *my_path = find_my_directory(tmpctx, argv0); - const char *prefix; + const char *rel; /* If we're running in-tree, all the subdaemons are with lightningd. */ if (has_all_subdaemons(my_path)) { @@ -547,14 +547,15 @@ static void find_subdaemons_and_plugins(struct lightningd *ld, const char *argv0 return; } - /* Assume we're running the installed version. Override - * for "make installccheck" though. */ - prefix = getenv("DEV_LIGHTNINGD_DESTDIR_PREFIX"); - if (!prefix) - prefix = ""; - ld->subdaemon_dir = tal_fmt(ld, "%s%s", prefix, PKGLIBEXECDIR); + /* OK, we're running the installed version? But we used to allow + * running in an arbitrary subtree, and people still do (plus, + * installcheck does this). So we use relative paths here. */ + rel = path_rel(NULL, BINDIR, PKGLIBEXECDIR); + ld->subdaemon_dir = path_join(ld, my_path, take(rel)); + + rel = path_rel(NULL, BINDIR, PLUGINDIR); plugins_set_builtin_plugins_dir(ld->plugins, - tal_fmt(tmpctx, "%s%s", prefix, PLUGINDIR)); + path_join(tmpctx, my_path, take(rel))); } /*~ We like to free everything on exit, so valgrind doesn't complain (valgrind