Skip to content

Commit 624d8b7

Browse files
committed
lightningd: fix up installs in subdirectories.
Commit a1fdeee "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. And we can't use path_rel, because that requires that the path exist (thanks @Lagrang3!). Fixes: #7595 Signed-off-by: Rusty Russell <[email protected]>
1 parent 48fa438 commit 624d8b7

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ CPATH := /usr/local/include
252252
LIBRARY_PATH := /usr/local/lib
253253
endif
254254

255-
CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1
255+
CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1
256256
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)
257257

258258
# If CFLAGS is already set in the environment of make (to whatever value, it
@@ -886,7 +886,7 @@ uninstall:
886886
installcheck: all-programs
887887
@rm -rf testinstall || true
888888
$(MAKE) DESTDIR=$$(pwd)/testinstall install
889-
DEV_LIGHTNINGD_DESTDIR_PREFIX=$$(pwd)/testinstall/ testinstall$(bindir)/lightningd --test-daemons-only --lightning-dir=testinstall
889+
testinstall$(bindir)/lightningd --test-daemons-only --lightning-dir=testinstall
890890
$(MAKE) DESTDIR=$$(pwd)/testinstall uninstall
891891
@if test `find testinstall '!' -type d | wc -l` -ne 0; then \
892892
echo 'make uninstall left some files in testinstall directory!'; \

lightningd/lightningd.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,37 @@ static const char *find_my_directory(const tal_t *ctx, const char *argv0)
530530
return path_dirname(ctx, take(me));
531531
}
532532

533+
/* How to get from abspath dir1 to abspath dir2? */
534+
static const char *relative(const tal_t *ctx, const char *dir1, const char *dir2)
535+
{
536+
char **dir1_parts, **dir2_parts;
537+
size_t common;
538+
char *backwards;
539+
540+
/* Collapse double /, and split into parts */
541+
dir1_parts = path_split(tmpctx, take(path_simplify(NULL, dir1)));
542+
dir2_parts = path_split(tmpctx, take(path_simplify(NULL, dir2)));
543+
544+
for (common = 0;
545+
dir1_parts[common]
546+
&& dir2_parts[common]
547+
&& streq(dir1_parts[common], dir2_parts[common]);
548+
common++);
549+
550+
/* We append .. for every non-shared part in dir1_parts */
551+
for (size_t i = common; dir1_parts[i]; i++)
552+
dir1_parts[i] = "..";
553+
554+
backwards = tal_strjoin(tmpctx, dir1_parts + common, PATH_SEP_STR, STR_TRAIL);
555+
return tal_fmt(ctx, "%s%s", backwards,
556+
tal_strjoin(tmpctx, dir2_parts + common, PATH_SEP_STR, STR_NO_TRAIL));
557+
}
558+
533559
/* Determine the correct daemon dir. */
534560
static void find_subdaemons_and_plugins(struct lightningd *ld, const char *argv0)
535561
{
536562
const char *my_path = find_my_directory(tmpctx, argv0);
537-
const char *prefix;
563+
const char *rel;
538564

539565
/* If we're running in-tree, all the subdaemons are with lightningd. */
540566
if (has_all_subdaemons(my_path)) {
@@ -547,14 +573,16 @@ static void find_subdaemons_and_plugins(struct lightningd *ld, const char *argv0
547573
return;
548574
}
549575

550-
/* Assume we're running the installed version. Override
551-
* for "make installccheck" though. */
552-
prefix = getenv("DEV_LIGHTNINGD_DESTDIR_PREFIX");
553-
if (!prefix)
554-
prefix = "";
555-
ld->subdaemon_dir = tal_fmt(ld, "%s%s", prefix, PKGLIBEXECDIR);
576+
/* OK, we're running the installed version? But we used to allow
577+
* running in an arbitrary subtree, and people still do (plus,
578+
* installcheck does this). So we use relative paths here. path_rel
579+
* doesn't work if the paths don't exist, so we use our own function. */
580+
rel = relative(NULL, BINDIR, PKGLIBEXECDIR);
581+
ld->subdaemon_dir = path_join(ld, my_path, take(rel));
582+
583+
rel = relative(NULL, BINDIR, PLUGINDIR);
556584
plugins_set_builtin_plugins_dir(ld->plugins,
557-
tal_fmt(tmpctx, "%s%s", prefix, PLUGINDIR));
585+
path_join(tmpctx, my_path, take(rel)));
558586
}
559587

560588
/*~ We like to free everything on exit, so valgrind doesn't complain (valgrind

0 commit comments

Comments
 (0)