plugin: Remember the shortname for a plugin

We use it in a couple of places, so let's remember it for easier
access.
This commit is contained in:
Christian Decker 2021-04-28 16:23:06 +02:00 committed by Rusty Russell
parent 2e27e4e443
commit cfb1107244
2 changed files with 8 additions and 6 deletions

View File

@ -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");

View File

@ -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;