common: only log io if they set --debug-subdaemon-io=<daemon> or with SIGUSR1.

Otherwise we just log the type of msg.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-02-05 14:39:28 +10:30
parent de56dc0ffc
commit c01f3267d5
7 changed files with 69 additions and 17 deletions

View File

@@ -10,13 +10,31 @@
#include <common/status.h>
#include <common/utils.h>
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <wire/wire.h>
#include <wire/peer_wire.h>
#include <wire/wire_sync.h>
static int status_fd = -1;
static struct daemon_conn *status_conn;
const void *trc;
volatile bool logging_io = false;
static void got_sigusr1(int signal)
{
logging_io = !logging_io;
}
static void setup_logging_sighandler(void)
{
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = got_sigusr1;
act.sa_flags = SA_RESTART;
sigaction(SIGUSR1, &act, NULL);
}
void status_setup_sync(int fd)
{
@@ -24,6 +42,7 @@ void status_setup_sync(int fd)
assert(!status_conn);
status_fd = fd;
trc = tal_tmpctx(NULL);
setup_logging_sighandler();
}
void status_setup_async(struct daemon_conn *master)
@@ -34,6 +53,7 @@ void status_setup_async(struct daemon_conn *master)
/* Don't use tmpctx here, otherwise debug_poll gets upset. */
trc = tal(NULL, char);
setup_logging_sighandler();
}
static bool too_large(size_t len, int type)
@@ -75,7 +95,7 @@ static void status_send_with_hdr(u16 type, const void *p, size_t len)
}
}
void status_io(enum log_level iodir, const u8 *p)
static void status_io_full(enum log_level iodir, const u8 *p)
{
u16 type = STATUS_LOG_MIN + iodir;
u8 *msg = tal_arr(NULL, u8, 0);
@@ -95,6 +115,21 @@ void status_io(enum log_level iodir, const u8 *p)
}
}
static void status_io_short(enum log_level iodir, const u8 *p)
{
status_debug("%s %s",
iodir == LOG_IO_OUT ? "peer_out" : "peer_in",
wire_type_name(fromwire_peektype(p)));
}
void status_io(enum log_level iodir, const u8 *p)
{
if (logging_io)
status_io_full(iodir, p);
else
status_io_short(iodir, p);
}
void status_vfmt(enum log_level level, const char *fmt, va_list ap)
{
char *str;

View File

@@ -27,6 +27,8 @@ void status_fmt(enum log_level level, const char *fmt, ...)
/* vprintf-style */
void status_vfmt(enum log_level level, const char *fmt, va_list ap);
/* Usually we only log the packet names, not contents. */
extern volatile bool logging_io;
void status_io(enum log_level iodir, const u8 *p);
/* Helpers */

View File

@@ -71,14 +71,12 @@ void subdaemon_setup(int argc, char *argv[])
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
#if DEVELOPER
for (int i = 1; i < argc; i++) {
if (strstarts(argv[i], "--dev-disconnect=")) {
dev_disconnect_init(atoi(argv[i]
+ strlen("--dev-disconnect=")));
}
if (streq(argv[i], "--log-io"))
logging_io = true;
}
#if DEVELOPER
/* From debugger, set debugger_spin to 0. */
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "--debugger")) {
@@ -87,6 +85,10 @@ void subdaemon_setup(int argc, char *argv[])
while (!debugger_connected)
usleep(10000);
}
if (strstarts(argv[i], "--dev-disconnect=")) {
dev_disconnect_init(atoi(argv[i]
+ strlen("--dev-disconnect=")));
}
}
#endif
}