Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/autoclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ static struct command_result *json_autocleaninvoice(struct command *cmd,
expired_by, cycle_seconds));
}

static void init(struct plugin_conn *prpc)
static void init(struct plugin_conn *prpc,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
rpc = prpc;

Expand All @@ -90,7 +91,7 @@ static const struct plugin_command commands[] = { {
int main(int argc, char *argv[])
{
setup_locale();
plugin_main(argv, init, commands, ARRAY_SIZE(commands),
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
plugin_option("autocleaninvoice-cycle",
"string",
"Perform cleanup of expired invoices every"
Expand Down
25 changes: 16 additions & 9 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ static struct command_result *
handle_getmanifest(struct command *getmanifest_cmd,
const struct plugin_command *commands,
size_t num_commands,
const struct plugin_option *opts)
const struct plugin_option *opts,
const enum plugin_restartability restartability)
{
struct json_out *params = json_out_new(tmpctx);

Expand Down Expand Up @@ -501,6 +502,7 @@ handle_getmanifest(struct command *getmanifest_cmd,
json_out_end(params, '}');
}
json_out_end(params, ']');
json_out_addstr(params, "dynamic", restartability == PLUGIN_RESTARTABLE ? "true" : "false");
json_out_end(params, '}');
json_out_finished(params);

Expand All @@ -511,21 +513,24 @@ static struct command_result *handle_init(struct command *init_cmd,
const char *buf,
const jsmntok_t *params,
const struct plugin_option *opts,
void (*init)(struct plugin_conn *))
void (*init)(struct plugin_conn *,
const char *buf, const jsmntok_t *))
{
const jsmntok_t *rpctok, *dirtok, *opttok, *t;
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *t;
struct sockaddr_un addr;
size_t i;
char *dir;
struct json_out *param_obj;

configtok = json_delve(buf, params, ".configuration");

/* Move into lightning directory: other files are relative */
dirtok = json_delve(buf, params, ".configuration.lightning-dir");
dirtok = json_delve(buf, configtok, ".lightning-dir");
dir = json_strdup(tmpctx, buf, dirtok);
if (chdir(dir) != 0)
plugin_err("chdir to %s: %s", dir, strerror(errno));

rpctok = json_delve(buf, params, ".configuration.rpc-file");
rpctok = json_delve(buf, configtok, ".rpc-file");
rpc_conn.fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (rpctok->end - rpctok->start + 1 > sizeof(addr.sun_path))
plugin_err("rpc filename '%.*s' too long",
Expand All @@ -545,7 +550,7 @@ static struct command_result *handle_init(struct command *init_cmd,
take(param_obj),
&rpc_conn,
".allow-deprecated-apis"),
"true");
"true");
opttok = json_get_member(buf, params, "options");
json_for_each_obj(i, t, opttok) {
char *opt = json_strdup(NULL, buf, t);
Expand All @@ -564,7 +569,7 @@ static struct command_result *handle_init(struct command *init_cmd,
}

if (init)
init(&rpc_conn);
init(&rpc_conn, buf, configtok);

return command_success_str(init_cmd, NULL);
}
Expand Down Expand Up @@ -698,7 +703,9 @@ void plugin_log(enum log_level l, const char *fmt, ...)
}

void plugin_main(char *argv[],
void (*init)(struct plugin_conn *rpc),
void (*init)(struct plugin_conn *rpc,
Comment thread
darosior marked this conversation as resolved.
const char *buf, const jsmntok_t *),
const enum plugin_restartability restartability,
const struct plugin_command *commands,
size_t num_commands, ...)
{
Expand Down Expand Up @@ -749,7 +756,7 @@ void plugin_main(char *argv[],
plugin_err("Expected getmanifest not %s", cmd->methodname);

membuf_consume(&request_conn.mb, reqlen);
handle_getmanifest(cmd, commands, num_commands, opts);
handle_getmanifest(cmd, commands, num_commands, opts, restartability);

cmd = read_json_request(tmpctx, &request_conn, &rpc_conn,
&params, &reqlen);
Expand Down
9 changes: 8 additions & 1 deletion plugins/libplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ struct plugin_conn;

extern bool deprecated_apis;

enum plugin_restartability {
PLUGIN_STATIC,
PLUGIN_RESTARTABLE
};

/* Create an array of these, one for each command you support. */
struct plugin_command {
const char *name;
Expand Down Expand Up @@ -147,7 +152,9 @@ char *charp_option(const char *arg, char **p);

/* The main plugin runner: append with 0 or more plugin_option(), then NULL. */
void NORETURN LAST_ARG_NULL plugin_main(char *argv[],
void (*init)(struct plugin_conn *rpc),
void (*init)(struct plugin_conn *rpc,
const char *buf, const jsmntok_t *),
const enum plugin_restartability restartability,
const struct plugin_command *commands,
size_t num_commands, ...);
#endif /* LIGHTNING_PLUGINS_LIBPLUGIN_H */
5 changes: 3 additions & 2 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,8 @@ static struct command_result *json_listpays(struct command *cmd,
take(json_out_obj(NULL, "bolt11", b11str)));
}

static void init(struct plugin_conn *rpc)
static void init(struct plugin_conn *rpc,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
const char *field;

Expand Down Expand Up @@ -1311,5 +1312,5 @@ static const struct plugin_command commands[] = { {
int main(int argc, char *argv[])
{
setup_locale();
plugin_main(argv, init, commands, ARRAY_SIZE(commands), NULL);
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands), NULL);
}