Skip to content

Commit 9a446c5

Browse files
comm: use ad hock function as show function inside ccan opt
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent 74db178 commit 9a446c5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

common/configdir.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ static void *opt_allocfn(size_t size)
4343
TAL_LABEL(opt_allocfn_notleak, ""));
4444
}
4545

46+
static void opt_show_longpath(char *buf, char *const *p)
47+
{
48+
if (*p){
49+
size_t len = strlen(*p);
50+
buf[0] = '"';
51+
strncpy(buf+1, *p, len);
52+
buf[1+len] = '"';
53+
buf[2+len] = '\0';
54+
}
55+
}
56+
4657
static void *tal_reallocfn(void *ptr, size_t size)
4758
{
4859
if (!ptr)
@@ -315,7 +326,7 @@ void initial_config_opts(const tal_t *ctx,
315326
/* Cmdline can also set lightning-dir. */
316327
*config_basedir = NULL;
317328
opt_register_early_arg("--lightning-dir=<dir>",
318-
opt_set_abspath, NULL,
329+
opt_set_abspath, opt_show_longpath,
319330
config_basedir,
320331
"Set base directory: network-specific subdirectory is under here");
321332

@@ -336,7 +347,7 @@ void initial_config_opts(const tal_t *ctx,
336347
/* If they set --conf it can still set --lightning-dir */
337348
if (!*config_filename) {
338349
opt_register_early_arg("--lightning-dir=<dir>",
339-
opt_restricted_forceconf_only, opt_show_charp,
350+
opt_restricted_forceconf_only, opt_show_longpath,
340351
config_basedir,
341352
"Set base directory: network-specific subdirectory is under here");
342353
} else {

lightningd/options.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ static void add_config(struct lightningd *ld,
15221522
{
15231523
char *name0 = tal_strndup(tmpctx, name, len);
15241524
char *answer = NULL;
1525-
char buf[OPT_SHOW_LEN + sizeof("...")];
1525+
char *buf = NULL;
15261526

15271527
#if DEVELOPER
15281528
if (strstarts(name0, "dev-")) {
@@ -1590,7 +1590,6 @@ static void add_config(struct lightningd *ld,
15901590
/* Ignore hidden options (deprecated) */
15911591
} else if (opt->show) {
15921592
opt->show(buf, opt->u.carg);
1593-
strcpy(buf + OPT_SHOW_LEN - 1, "...");
15941593

15951594
if (streq(buf, "true") || streq(buf, "false")
15961595
|| (!streq(buf, "") && strspn(buf, "0123456789.") == strlen(buf))) {

0 commit comments

Comments
 (0)