status: use common status codes for all the failures.
This change is really to allow us to have a --dev-fail-on-subdaemon-fail option so we can handle failures from subdaemons generically. It also neatens handling so we can have an explicit callback for "peer did something wrong" (which matters if we want to close the channel in that case). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
f219955dc6
commit
ef28b6112c
@@ -11,7 +11,7 @@
|
||||
/* We only support one channel per peer anyway */
|
||||
void peer_failed(int peer_fd, struct crypto_state *cs,
|
||||
const struct channel_id *channel_id,
|
||||
u16 error_code, const char *fmt, ...)
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
const char *errmsg;
|
||||
@@ -39,5 +39,5 @@ void peer_failed(int peer_fd, struct crypto_state *cs,
|
||||
io_fd_block(peer_fd, false);
|
||||
sync_crypto_write(cs, peer_fd, take(msg));
|
||||
|
||||
status_failed(error_code, "%s", errmsg);
|
||||
status_failed(STATUS_FAIL_PEER_BAD, "%s", errmsg);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ struct channel_id;
|
||||
* @peer_fd: file descriptor for peer.
|
||||
* @cs: the peer's current crypto state.
|
||||
* @channel_id: channel with error, or NULL for all.
|
||||
* @error_code: error code as per status_failed
|
||||
* @fmt: format as per status_failed
|
||||
* @fmt: format as per status_failed(STATUS_FAIL_PEER_BAD,
|
||||
*/
|
||||
void peer_failed(int peer_fd, struct crypto_state *cs,
|
||||
const struct channel_id *channel_id,
|
||||
u16 error_code, const char *fmt, ...)
|
||||
PRINTF_FMT(5,6) NORETURN;
|
||||
const char *fmt, ...)
|
||||
PRINTF_FMT(4,5) NORETURN;
|
||||
#endif /* LIGHTNING_COMMON_PEER_FAILED_H */
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <common/daemon_conn.h>
|
||||
#include <common/status.h>
|
||||
#include <common/utils.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <wire/wire.h>
|
||||
#include <wire/wire_sync.h>
|
||||
@@ -88,7 +89,7 @@ void status_trace(const char *fmt, ...)
|
||||
trc = tal_tmpctx(NULL);
|
||||
}
|
||||
|
||||
void status_failed(u16 code, const char *fmt, ...)
|
||||
void status_failed(enum status_fail code, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *str;
|
||||
@@ -107,3 +108,14 @@ void status_failed(u16 code, const char *fmt, ...)
|
||||
|
||||
exit(0x80 | (code & 0xFF));
|
||||
}
|
||||
|
||||
void master_badmsg(u32 type_expected, const u8 *msg)
|
||||
{
|
||||
if (!msg)
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
"failed reading msg %u: %s",
|
||||
type_expected, strerror(errno));
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
"Error parsing %u: %s",
|
||||
type_expected, tal_hex(trc, msg));
|
||||
}
|
||||
|
||||
@@ -20,11 +20,41 @@ extern const void *trc;
|
||||
/* Failure codes always have high bit set. */
|
||||
#define STATUS_FAIL 0x8000
|
||||
|
||||
/* These are always followed by an ASCII string. */
|
||||
enum status_fail {
|
||||
/*
|
||||
* These errors shouldn't happen:
|
||||
*/
|
||||
/* Master daemon sent unknown/malformed command, or fd failed */
|
||||
STATUS_FAIL_MASTER_IO = STATUS_FAIL,
|
||||
|
||||
/* Hsmd sent unknown/malformed command, or fd failed */
|
||||
STATUS_FAIL_HSM_IO,
|
||||
|
||||
/* Gossipd sent unknown/malformed command, or fd failed */
|
||||
STATUS_FAIL_GOSSIP_IO,
|
||||
|
||||
/* Other internal error. */
|
||||
STATUS_FAIL_INTERNAL_ERROR,
|
||||
|
||||
/*
|
||||
* These errors happen when the other peer misbehaves:
|
||||
*/
|
||||
/* I/O failure (probably they closed the socket) */
|
||||
STATUS_FAIL_PEER_IO,
|
||||
/* Peer did something else wrong */
|
||||
STATUS_FAIL_PEER_BAD
|
||||
};
|
||||
|
||||
/* Send a message (frees the message). */
|
||||
void status_send_sync(const u8 *msg);
|
||||
/* Send a printf-style debugging trace. */
|
||||
void status_trace(const char *fmt, ...) PRINTF_FMT(1,2);
|
||||
/* Send a failure status code with printf-style msg, and exit. */
|
||||
void status_failed(u16 code, const char *fmt, ...) PRINTF_FMT(2,3) NORETURN;
|
||||
void status_failed(enum status_fail, const char *fmt, ...) PRINTF_FMT(2,3) NORETURN;
|
||||
|
||||
/* Helper for master failures: sends STATUS_FAIL_MASTER_IO.
|
||||
* msg NULL == read failure. */
|
||||
void master_badmsg(u32 type_expected, const u8 *msg);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_STATUS_H */
|
||||
|
||||
Reference in New Issue
Block a user