MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_register

Function plugin_register

lightningd/plugin.c:326–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES,
327 struct plugin_command *start_cmd, bool important,
328 const char *parambuf STEALS,
329 const jsmntok_t *params STEALS)
330{
331 struct plugin *p, *p_temp;
332 char* abspath;
333 u32 chksum;
334
335 abspath = path_canon(tmpctx, path);
336 if (!abspath) {
337 return NULL;
338 }
339 /* Don't register an already registered plugin */
340 list_for_each(&plugins->plugins, p_temp, list) {
341 if (streq(abspath, p_temp->cmd)) {
342 /* If added as "important", upgrade to "important". */
343 if (important)
344 p_temp->important = true;
345 /* stop and restart plugin on different checksum */
346 chksum = file_checksum(plugins->ld, path);
347 if (p_temp->checksum != chksum && !p_temp->important) {
348 plugin_kill(p_temp, LOG_INFORM,
349 "Plugin changed, needs restart.");
350 break;
351 }
352 tal_free_if_taken(path);
353 return NULL;
354 }
355 }
356
357 p = tal(plugins, struct plugin);
358 p->plugins = plugins;
359 p->cmd = tal_steal(p, abspath);
360 p->checksum = file_checksum(plugins->ld, p->cmd);
361 p->shortname = path_basename(p, p->cmd);
362 p->start_cmd = start_cmd;
363 p->can_check = false;
364
365 p->plugin_state = UNCONFIGURED;
366 list_head_init(&p->jsouts);
367 p->notification_topics = tal_arr(p, const char *, 0);
368 p->subscriptions = NULL;
369 p->dynamic = false;
370 p->index = plugins->plugin_idx++;
371 p->stdout_conn = NULL;
372
373 p->log = new_logger(p, plugins->ld->log_book, NULL, "plugin-%s", p->shortname);
374 p->methods = tal_arr(p, const char *, 0);
375 list_head_init(&p->plugin_opts);
376
377 list_add_tail(&plugins->plugins, &p->list);
378 tal_add_destructor(p, destroy_plugin);
379 strmap_init(&p->pending_requests);
380 memleak_add_helper(p, memleak_help_pending_requests);
381
382 p->important = important;
383 p->parambuf = tal_steal(p, parambuf);

Callers 5

opt_add_pluginFunction · 0.85
opt_important_pluginFunction · 0.85
add_plugin_dirFunction · 0.85
plugin_dynamic_startFunction · 0.85

Calls 7

path_canonFunction · 0.85
file_checksumFunction · 0.85
plugin_killFunction · 0.85
tal_free_if_takenFunction · 0.85
path_basenameFunction · 0.85
list_head_initFunction · 0.85
new_loggerFunction · 0.70

Tested by

no test coverage detected