| 2431 | } |
| 2432 | |
| 2433 | void plugin_main(char *argv[], |
| 2434 | const char *(*init)(struct command *init_cmd, |
| 2435 | const char *buf, const jsmntok_t *), |
| 2436 | void *data, |
| 2437 | const enum plugin_restartability restartability, |
| 2438 | bool init_rpc, |
| 2439 | struct feature_set *features STEALS, |
| 2440 | const struct plugin_command *commands TAKES, |
| 2441 | size_t num_commands, |
| 2442 | const struct plugin_notification *notif_subs TAKES, |
| 2443 | size_t num_notif_subs, |
| 2444 | const struct plugin_hook *hook_subs TAKES, |
| 2445 | size_t num_hook_subs, |
| 2446 | const char **notif_topics TAKES, |
| 2447 | size_t num_notif_topics, |
| 2448 | ...) |
| 2449 | { |
| 2450 | struct plugin *plugin; |
| 2451 | va_list ap; |
| 2452 | bool developer; |
| 2453 | |
| 2454 | setup_locale(); |
| 2455 | |
| 2456 | developer = daemon_developer_mode(argv); |
| 2457 | |
| 2458 | /* Note this already prints to stderr, which is enough for now */ |
| 2459 | daemon_setup(argv[0], NULL, NULL); |
| 2460 | |
| 2461 | va_start(ap, num_notif_topics); |
| 2462 | plugin = new_plugin(NULL, argv[0], developer, |
| 2463 | init, restartability, init_rpc, features, commands, |
| 2464 | num_commands, notif_subs, num_notif_subs, hook_subs, |
| 2465 | num_hook_subs, notif_topics, num_notif_topics, ap); |
| 2466 | plugin_set_data(plugin, data); |
| 2467 | va_end(ap); |
| 2468 | setup_command_usage(plugin); |
| 2469 | |
| 2470 | timers_init(&plugin->timers, time_mono()); |
| 2471 | |
| 2472 | io_new_conn(plugin, STDIN_FILENO, stdin_conn_init, plugin); |
| 2473 | io_new_conn(plugin, STDOUT_FILENO, stdout_conn_init, plugin); |
| 2474 | |
| 2475 | for (;;) { |
| 2476 | struct timer *expired = NULL; |
| 2477 | |
| 2478 | clean_tmpctx(); |
| 2479 | |
| 2480 | /* Will only exit if a timer has expired. */ |
| 2481 | io_loop(&plugin->timers, &expired); |
| 2482 | call_plugin_timer(plugin, expired); |
| 2483 | } |
| 2484 | |
| 2485 | tal_free(plugin); |
| 2486 | } |
| 2487 | |
| 2488 | static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx, |
| 2489 | const char *buffer, |