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;
|
|
|
|
|
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
|
|
|
|
|
|
|
/* Convenient context, frees up after every status_update/failed */
|
|
|
|
extern const void *trc;
|
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* Send a printf-style debugging trace. */
|
|
|
|
void status_fmt(enum log_level level, const char *fmt, ...)
|
|
|
|
PRINTF_FMT(2,3);
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* vprintf-style */
|
|
|
|
void status_vfmt(enum log_level level, 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;
|
2018-02-05 05:09:28 +01:00
|
|
|
void status_io(enum log_level iodir, const u8 *p);
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* Helpers */
|
|
|
|
#define status_debug(...) \
|
|
|
|
status_fmt(LOG_DBG, __VA_ARGS__)
|
|
|
|
#define status_info(...) \
|
|
|
|
status_fmt(LOG_INFORM, __VA_ARGS__)
|
|
|
|
#define status_unusual(...) \
|
|
|
|
status_fmt(LOG_UNUSUAL, __VA_ARGS__)
|
|
|
|
#define status_broken( ...) \
|
|
|
|
status_fmt(LOG_BROKEN, __VA_ARGS__)
|
2017-09-12 06:55:52 +02:00
|
|
|
|
2018-02-05 05:09:27 +01:00
|
|
|
/* FIXME: Transition */
|
|
|
|
#define status_trace(...) status_debug(__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);
|
2018-02-19 02:06:15 +01:00
|
|
|
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2) NORETURN;
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_STATUS_H */
|