Skip to content

Commit de67b73

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 de67b73

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

common/configdir.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ char *opt_set_talstr(const char *arg, char **p)
2626

2727
static char *opt_set_abspath(const char *arg, char **p)
2828
{
29-
char* ret;
3029
tal_free(*p);
31-
32-
ret = opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),p);
33-
if (strlen(*p) > OPT_SHOW_LEN)
34-
errx(EXITCODE_INVALID_PATH, "absolute path of command line option exceeds %d chars: '%s'",
35-
OPT_SHOW_LEN, *p);
36-
return ret;
30+
return opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),
31+
p);
3732
}
3833

3934
/* Tal wrappers for opt. */
@@ -43,6 +38,17 @@ static void *opt_allocfn(size_t size)
4338
TAL_LABEL(opt_allocfn_notleak, ""));
4439
}
4540

41+
static void opt_show_longpath(char *buf, char *const *p)
42+
{
43+
if (*p){
44+
size_t len = strlen(*p);
45+
buf[0] = '"';
46+
strncpy(buf+1, *p, len);
47+
buf[1+len] = '"';
48+
buf[2+len] = '\0';
49+
}
50+
}
51+
4652
static void *tal_reallocfn(void *ptr, size_t size)
4753
{
4854
if (!ptr)
@@ -315,7 +321,7 @@ void initial_config_opts(const tal_t *ctx,
315321
/* Cmdline can also set lightning-dir. */
316322
*config_basedir = NULL;
317323
opt_register_early_arg("--lightning-dir=<dir>",
318-
opt_set_abspath, NULL,
324+
opt_set_abspath, opt_show_longpath,
319325
config_basedir,
320326
"Set base directory: network-specific subdirectory is under here");
321327

@@ -336,7 +342,7 @@ void initial_config_opts(const tal_t *ctx,
336342
/* If they set --conf it can still set --lightning-dir */
337343
if (!*config_filename) {
338344
opt_register_early_arg("--lightning-dir=<dir>",
339-
opt_restricted_forceconf_only, opt_show_charp,
345+
opt_restricted_forceconf_only, opt_show_longpath,
340346
config_basedir,
341347
"Set base directory: network-specific subdirectory is under here");
342348
} 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 = tal(NULL, char);
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)