Skip to content

Commit

Permalink
Cleaned up --alt-subdaemon implementation per suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Jan 28, 2020
1 parent c52235c commit 1b1bbdf
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,33 +219,26 @@ static char *opt_alt_subdaemon(const char *arg, struct lightningd *ld)
{
char *subdaemon;
char *sdpath;
char *prevname;
char *prevval;

/* example arg: "lightning_hsmd:remote_hsmd" */
char *argbuf = tal_strdup(ld, arg);
char *colon = strchr(argbuf, ':');
if (!colon)
return tal_fmt(NULL, "argument must contain \':\'");
*colon = '\0';

if (!is_subdaemon(argbuf))
return tal_fmt(NULL, "%s is not a subdaemon", argbuf);

subdaemon = tal_strdup(ld, argbuf);

/* Remove any preexisting alt subdaemon mapping. */
prevname = strmap_del(&ld->alt_subdaemons, subdaemon,
(const char **) &prevval);
if (prevname) {
tal_free(prevname);
tal_free(prevval);
}

sdpath = tal_strdup(ld, colon+1);
size_t colonoff = strcspn(arg, ":");
if (!arg[colonoff])
return tal_fmt(NULL, "argument must contain ':'");

subdaemon = tal_strndup(ld, arg, colonoff);
if (!is_subdaemon(subdaemon))
return tal_fmt(NULL, "\"%s\" is not a subdaemon", subdaemon);

/* Make the value a tal-child of the subdaemon */
sdpath = tal_strdup(subdaemon, arg + colonoff + 1);

/* Remove any preexisting alt subdaemon mapping (and
* implicitly, the sdpath). */
tal_free(strmap_del(&ld->alt_subdaemons, subdaemon, NULL));

strmap_add(&ld->alt_subdaemons, subdaemon, sdpath);

tal_free(argbuf);
return NULL;
}

Expand Down Expand Up @@ -1174,13 +1167,9 @@ struct json_add_opt_alt_subdaemon_args {
};

static bool json_add_opt_alt_subdaemon(const char *member,
void *valuev,
void *argpv)
const char *value,
struct json_add_opt_alt_subdaemon_args *argp)
{
struct json_add_opt_alt_subdaemon_args *argp =
(struct json_add_opt_alt_subdaemon_args *) argpv;
const char *value = (const char *) valuev;

json_add_string(argp->response,
argp->name0,
tal_fmt(argp->name0, "%s:%s", member, value));
Expand Down

0 comments on commit 1b1bbdf

Please sign in to comment.