2017-08-29 01:36:01 +09:30
|
|
|
#ifndef LIGHTNING_COMMON_STATUS_H
|
|
|
|
#define LIGHTNING_COMMON_STATUS_H
|
2017-01-10 15:24:20 +10:30
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/compiler/compiler.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-02-19 11:36:15 +10:30
|
|
|
#include <ccan/take/take.h>
|
2018-02-05 14:39:27 +10:30
|
|
|
#include <common/status_levels.h>
|
2017-10-11 20:32:50 +10:30
|
|
|
#include <stdarg.h>
|
2018-02-05 14:39:27 +10:30
|
|
|
#include <stdbool.h>
|
2017-01-10 15:24:20 +10:30
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-02-08 11:55:12 +10:30
|
|
|
struct channel_id;
|
2017-03-20 07:02:44 +10:30
|
|
|
struct daemon_conn;
|
|
|
|
|
2017-01-10 15:24:20 +10:30
|
|
|
/* Simple status reporting API. */
|
2017-03-20 07:02:44 +10:30
|
|
|
void status_setup_sync(int fd);
|
|
|
|
void status_setup_async(struct daemon_conn *master);
|
2017-01-10 15:24:20 +10:30
|
|
|
|
2018-02-05 14:39:27 +10:30
|
|
|
/* Send a printf-style debugging trace. */
|
|
|
|
void status_fmt(enum log_level level, const char *fmt, ...)
|
|
|
|
PRINTF_FMT(2,3);
|
2017-09-12 14:25:52 +09:30
|
|
|
|
2018-02-05 14:39:27 +10:30
|
|
|
/* vprintf-style */
|
|
|
|
void status_vfmt(enum log_level level, const char *fmt, va_list ap);
|
2017-09-12 14:25:52 +09:30
|
|
|
|
2018-02-05 14:39:28 +10:30
|
|
|
/* Usually we only log the packet names, not contents. */
|
|
|
|
extern volatile bool logging_io;
|
2018-05-10 08:48:24 +09:30
|
|
|
void status_peer_io(enum log_level iodir, const u8 *p);
|
|
|
|
void status_io(enum log_level iodir, const char *who,
|
|
|
|
const void *data, size_t len);
|
2017-09-12 14:25:52 +09:30
|
|
|
|
2018-02-05 14:39:27 +10:30
|
|
|
/* 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 14:25:52 +09:30
|
|
|
|
2018-02-05 14:39:27 +10:30
|
|
|
/* FIXME: Transition */
|
|
|
|
#define status_trace(...) status_debug(__VA_ARGS__)
|
2017-09-12 14:25:52 +09:30
|
|
|
|
2017-01-10 15:24:20 +10:30
|
|
|
/* Send a failure status code with printf-style msg, and exit. */
|
2018-02-08 11:55:12 +10:30
|
|
|
void status_failed(enum status_failreason code,
|
|
|
|
const char *fmt, ...) PRINTF_FMT(2,3) NORETURN;
|
2017-09-12 14:25:52 +09:30
|
|
|
|
2018-02-08 11:55:12 +10:30
|
|
|
/* Helper for master failures: sends STATUS_FATAL_MASTER_IO.
|
2017-09-12 14:25:52 +09:30
|
|
|
* msg NULL == read failure. */
|
2018-02-08 11:55:12 +10:30
|
|
|
void master_badmsg(u32 type_expected, const u8 *msg) NORETURN;
|
|
|
|
|
2018-02-23 16:23:47 +10:30
|
|
|
void status_send(const u8 *msg TAKES);
|
2018-02-19 11:36:15 +10:30
|
|
|
void status_send_fatal(const u8 *msg TAKES, int fd1, int fd2) NORETURN;
|
2017-08-29 01:36:01 +09:30
|
|
|
#endif /* LIGHTNING_COMMON_STATUS_H */
|