mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
plugin: Make plugin_kill a printf-like function
Suggested-by: Rusty Russell <@rustyrussell> Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
parent
82393036e3
commit
b8a1445317
1 changed files with 16 additions and 14 deletions
|
@ -131,8 +131,15 @@ void plugin_register(struct plugins *plugins, const char* path TAKES)
|
|||
/**
|
||||
* Kill a plugin process, with an error message.
|
||||
*/
|
||||
static void plugin_kill(struct plugin *plugin, char *msg)
|
||||
static void PRINTF_FMT(2,3) plugin_kill(struct plugin *plugin, char *fmt, ...)
|
||||
{
|
||||
char *msg;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msg = tal_vfmt(plugin, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
log_broken(plugin->log, "Killing plugin: %s", msg);
|
||||
plugin->stop = true;
|
||||
io_wake(plugin);
|
||||
|
@ -507,29 +514,24 @@ static bool plugin_rpcmethod_add(struct plugin *plugin, const char *buffer,
|
|||
longdesctok = json_get_member(buffer, meth, "long_description");
|
||||
|
||||
if (!nametok || nametok->type != JSMN_STRING) {
|
||||
plugin_kill(
|
||||
plugin,
|
||||
tal_fmt(plugin,
|
||||
plugin_kill(plugin,
|
||||
"rpcmethod does not have a string \"name\": %.*s",
|
||||
meth->end - meth->start, buffer + meth->start));
|
||||
meth->end - meth->start, buffer + meth->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!desctok || desctok->type != JSMN_STRING) {
|
||||
plugin_kill(plugin, tal_fmt(plugin,
|
||||
"rpcmethod does not have a string "
|
||||
"\"description\": %.*s",
|
||||
meth->end - meth->start,
|
||||
buffer + meth->start));
|
||||
plugin_kill(plugin,
|
||||
"rpcmethod does not have a string "
|
||||
"\"description\": %.*s",
|
||||
meth->end - meth->start, buffer + meth->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (longdesctok && longdesctok->type != JSMN_STRING) {
|
||||
plugin_kill(
|
||||
plugin,
|
||||
tal_fmt(plugin,
|
||||
plugin_kill(plugin,
|
||||
"\"long_description\" is not a string: %.*s",
|
||||
meth->end - meth->start, buffer + meth->start));
|
||||
meth->end - meth->start, buffer + meth->start);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue