Skip to content

Commit

Permalink
comm: use ad hock function as show function inside ccan opt
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jan 11, 2023
1 parent 74db178 commit 210bf8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions common/configdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ char *opt_set_talstr(const char *arg, char **p)

static char *opt_set_abspath(const char *arg, char **p)
{
char* ret;
tal_free(*p);

ret = opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),p);
if (strlen(*p) > OPT_SHOW_LEN)
errx(EXITCODE_INVALID_PATH, "absolute path of command line option exceeds %d chars: '%s'",
OPT_SHOW_LEN, *p);
return ret;
return opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),
p);
}

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

static void opt_show_longpath(char *buf, char *const *p)
{
if (*p){
size_t len = strlen(*p);
buf[0] = '"';
strncpy(buf+1, *p, len);
buf[1+len] = '"';
buf[2+len] = '\0';
}
}

static void *tal_reallocfn(void *ptr, size_t size)
{
if (!ptr)
Expand Down Expand Up @@ -315,7 +321,7 @@ void initial_config_opts(const tal_t *ctx,
/* Cmdline can also set lightning-dir. */
*config_basedir = NULL;
opt_register_early_arg("--lightning-dir=<dir>",
opt_set_abspath, NULL,
opt_set_abspath, opt_show_longpath,
config_basedir,
"Set base directory: network-specific subdirectory is under here");

Expand All @@ -336,7 +342,7 @@ void initial_config_opts(const tal_t *ctx,
/* If they set --conf it can still set --lightning-dir */
if (!*config_filename) {
opt_register_early_arg("--lightning-dir=<dir>",
opt_restricted_forceconf_only, opt_show_charp,
opt_restricted_forceconf_only, opt_show_longpath,
config_basedir,
"Set base directory: network-specific subdirectory is under here");
} else {
Expand Down
4 changes: 2 additions & 2 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,8 @@ static void add_config(struct lightningd *ld,
{
char *name0 = tal_strndup(tmpctx, name, len);
char *answer = NULL;
char buf[OPT_SHOW_LEN + sizeof("...")];
// FIXME(vincenzopalazzo): accept arbitrary length
char buf[256];

#if DEVELOPER
if (strstarts(name0, "dev-")) {
Expand Down Expand Up @@ -1590,7 +1591,6 @@ static void add_config(struct lightningd *ld,
/* Ignore hidden options (deprecated) */
} else if (opt->show) {
opt->show(buf, opt->u.carg);
strcpy(buf + OPT_SHOW_LEN - 1, "...");

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

0 comments on commit 210bf8c

Please sign in to comment.