2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_STATUS_H
|
|
|
|
#define LIGHTNING_COMMON_STATUS_H
|
2017-01-10 05:54:20 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/compiler/compiler.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-02-19 02:06:15 +01:00
|
|
|
#include <ccan/take/take.h>
|
2018-02-05 05:09:27 +01:00
|
|
|
#include <common/status_levels.h>
|
2017-10-11 12:02:50 +02:00
|
|
|
#include <stdarg.h>
|
2018-02-05 05:09:27 +01:00
|
|
|
#include <stdbool.h>
|
2017-01-10 05:54:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
struct channel_id;
|
2017-03-19 21:32:44 +01:00
|
|
|
struct daemon_conn;
|
2019-11-17 12:42:33 +01:00
|
|
|
struct node_id;
|
2019-06-03 20:11:25 +02:00
|
|
|
struct per_peer_state;
|
2017-03-19 21:32:44 +01:00
|
|
|
|
2017-01-10 05:54:20 +01:00
|
|
|
/* Simple status reporting API. */
|
2017-03-19 21:32:44 +01:00
|
|
|
void status_setup_sync(int fd);
|
|
|
|
void status_setup_async(struct daemon_conn *master);
|
2017-01-10 05:54:20 +01:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* Send a printf-style debugging trace. */
|
2019-11-17 12:42:33 +01:00
|
|
|
void status_fmt(enum log_level level,
|
|
|
|
const struct node_id *peer,
|
|
|
|
const char *fmt, ...)
|
|
|
|
PRINTF_FMT(3,4);
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* vprintf-style */
|
2019-11-17 12:42:33 +01:00
|
|
|
void status_vfmt(enum log_level level,
|
|
|
|
const struct node_id *peer,
|
|
|
|
const char *fmt, va_list ap);
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:28 +01:00
|
|
|
/* Usually we only log the packet names, not contents. */
|
|
|
|
extern volatile bool logging_io;
|
2019-11-17 12:42:33 +01:00
|
|
|
|
|
|
|
/* This logs a debug summary if IO logging not enabled. */
|
|
|
|
void status_peer_io(enum log_level iodir,
|
|
|
|
const struct node_id *peer,
|
|
|
|
const u8 *p);
|
|
|
|
void status_io(enum log_level iodir,
|
|
|
|
const struct node_id *peer,
|
|
|
|
const char *who,
|
2018-05-10 01:18:24 +02:00
|
|
|
const void *data, size_t len);
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* Helpers */
|
|
|
|
#define status_debug(...) \
|
2019-11-17 12:42:33 +01:00
|
|
|
status_fmt(LOG_DBG, NULL, __VA_ARGS__)
|
2018-02-05 05:09:27 +01:00
|
|
|
#define status_info(...) \
|
2019-11-17 12:42:33 +01:00
|
|
|
status_fmt(LOG_INFORM, NULL, __VA_ARGS__)
|
2018-02-05 05:09:27 +01:00
|
|
|
#define status_unusual(...) \
|
2019-11-17 12:42:33 +01:00
|
|
|
status_fmt(LOG_UNUSUAL, NULL, __VA_ARGS__)
|
2018-02-05 05:09:27 +01:00
|
|
|
#define status_broken( ...) \
|
2019-11-17 12:42:33 +01:00
|
|
|
status_fmt(LOG_BROKEN, NULL, __VA_ARGS__)
|
|
|
|
|
|
|
|
/* For daemons which handle multiple peers */
|
|
|
|
#define status_peer_debug(peer, ...) \
|
|
|
|
status_fmt(LOG_DBG, (peer), __VA_ARGS__)
|
|
|
|
#define status_peer_info(peer, ...) \
|
|
|
|
status_fmt(LOG_INFORM, (peer), __VA_ARGS__)
|
|
|
|
#define status_peer_unusual(peer, ...) \
|
|
|
|
status_fmt(LOG_UNUSUAL, (peer), __VA_ARGS__)
|
|
|
|
#define status_peer_broken(peer, ...) \
|
|
|
|
status_fmt(LOG_BROKEN, (peer), __VA_ARGS__)
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2017-01-10 05:54:20 +01:00
|
|
|
/* Send a failure status code with printf-style msg, and exit. */
|
2018-02-08 02:25:12 +01:00
|
|
|
void status_failed(enum status_failreason code,
|
|
|
|
const char *fmt, ...) PRINTF_FMT(2,3) NORETURN;
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
/* Helper for master failures: sends STATUS_FATAL_MASTER_IO.
|
2017-09-12 06:55:52 +02:00
|
|
|
* msg NULL == read failure. */
|
2018-02-08 02:25:12 +01:00
|
|
|
void master_badmsg(u32 type_expected, const u8 *msg) NORETURN;
|
|
|
|
|
2018-02-23 06:53:47 +01:00
|
|
|
void status_send(const u8 *msg TAKES);
|
2019-06-03 20:11:25 +02:00
|
|
|
void status_send_fatal(const u8 *msg TAKES) NORETURN;
|
|
|
|
|
|
|
|
/* Only for sync status! */
|
|
|
|
void status_send_fd(int fd);
|
2021-09-06 14:39:27 +02:00
|
|
|
|
|
|
|
#if DEVELOPER
|
|
|
|
/* Print BROKEN status: callback for dump_memleak. */
|
|
|
|
void memleak_status_broken(const char *fmt, ...);
|
|
|
|
#endif
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_STATUS_H */
|