From cfb110724464f0b3fb18f3b91529c5b250b7742c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 28 Apr 2021 16:23:06 +0200 Subject: [PATCH] plugin: Remember the shortname for a plugin We use it in a couple of places, so let's remember it for easier access. --- lightningd/plugin.c | 9 +++------ lightningd/plugin.h | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 57b9e5e9b..4f4e85866 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -240,6 +240,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES, p = tal(plugins, struct plugin); p->plugins = plugins; p->cmd = tal_strdup(p, path); + p->shortname = path_basename(p, p->cmd); p->start_cmd = start_cmd; p->plugin_state = UNCONFIGURED; @@ -250,8 +251,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES, p->dynamic = false; p->index = plugins->plugin_idx++; - p->log = new_log(p, plugins->log_book, NULL, "plugin-%s", - path_basename(tmpctx, p->cmd)); + p->log = new_log(p, plugins->log_book, NULL, "plugin-%s", p->shortname); p->methods = tal_arr(p, const char *, 0); list_head_init(&p->plugin_opts); @@ -1858,7 +1858,6 @@ void json_add_opt_plugins_array(struct json_stream *response, bool important) { struct plugin *p; - const char *plugin_name; struct plugin_opt *opt; const char *opt_name; @@ -1873,9 +1872,7 @@ void json_add_opt_plugins_array(struct json_stream *response, json_add_string(response, "path", p->cmd); /* FIXME: use executables basename until plugins can define their names */ - plugin_name = path_basename(NULL, p->cmd); - json_add_string(response, "name", plugin_name); - tal_free(plugin_name); + json_add_string(response, "name", p->shortname); if (!list_empty(&p->plugin_opts)) { json_object_start(response, "options"); diff --git a/lightningd/plugin.h b/lightningd/plugin.h index e31e642b1..9fae129cf 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -39,8 +39,13 @@ enum plugin_state { * A plugin, exposed as a stub so we can pass it as an argument. */ struct plugin { + /* Must be first element in the struct otherwise we get false + * positives for leaks. */ struct list_node list; + /* The filename that can be used to refer to the plugin. */ + const char *shortname; + pid_t pid; char *cmd; struct io_conn *stdin_conn, *stdout_conn;