Commit Graph

27 Commits

Author SHA1 Message Date
Rusty Russell 4aeebe88f2 log: fix ltmp crash.
When we clear and recreate ltmp, we attach it to whatever logbook it's on.
This, of course, is fraught, since it may be freed.

We could make it NULL-parented, but that makes YA special-case to free
when we exit (we try to keep valgrind happy by freeing everything).  So
since the first log_book is the permanent one attached to lightningd,
just keep that parent when we re-build it after use.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-20 12:58:13 +01:00
Rusty Russell d2f691b288 subd: make functions more generic, don't assume 'struct channel'.
This means the caller needs to supply an explicit log to base the
subd log on, and also a callback for error handling.

The callback is kind of ugly, but it gets reworked towards the end
of this series.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-19 02:56:51 +00:00
Rusty Russell a2c6ec6c9b lightningd: use tal_link for log_book.
BackgroundL Each log has a log_book: many logs can share the same one,
as each one can have a separate prefix.

Testing tickled a bug at the end of this series, where subd was
logging to the peer's log_book on shutdown, but the peer was already
freed.  We've already had issues with logging while lightningd is
shutting down.

There are times when reference counting really is the right answer,
this seems to be one of them: the 'struct log' share the 'struct
log_book' and the last 'struct log' cleans it up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-19 02:56:51 +00:00
Christian Decker e92e26f84d json-rpc: Check for unprintable characters in JSON-RPC commands
As reported by @practicalswift in #945 it is possible to inject
non-printable, or shell escape, characters in a json command, that
will fail to parse and then clear the shell.

Reported-by: @practicalswift
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-10 15:44:14 +01:00
Rusty Russell e2eb694619 Use common loglevel JSON parser.
This now means we can ask for IO logs for peers, too (that case was missing!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-07 00:46:49 +00:00
Rusty Russell b7acd93578 log: separate levels for IO directions, allow msg + io data.
We currently don't handle LOG_IO properly, and we turn it into a string
before handing it to the ->print function, which makes it ugly for
the case where we're using copy_to_parent_log, and also means in
that case we lose *what peer* the IO is coming from.

Now, we handle the io as a separate arg, which is much neater.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-07 00:46:49 +00:00
Rusty Russell 4856ca5db0 json_log: move command to log.c, share code with listpeers log.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-07 00:46:49 +00:00
Rusty Russell c076534220 logv: preserve errno.
Logging often gets called in error paths, so this is just good hygiene.
Also, log_io does this already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-07 00:46:49 +00:00
Wladimir J. van der Laan 1ef79854c3 lightningd: Don't crash when libunwind backtrace not available
libunwind does not accept a NULL parameter for the error callback. It
will simply call into the NULL pointer. So add an error callback.

This makes the crash output somewhat more sensible on FreeBSD, where
there is no libunwind stack trace available:

    2018-02-05T20:24:50.598Z lightningd(75556): error getting backtrace: no stack trace because unwind library not available (0)

Signed-off-by: Wladimir J. van der Laan <laanwj@gmail.com>
2018-02-06 01:35:31 +00:00
practicalswift 98372e4c0a Mark last parameter of log_to_stdout(...) as intentionally unused 2018-02-02 20:34:22 +01:00
practicalswift d09fc71456 Rename log_default_print to log_to_stdout 2018-02-02 00:55:38 +00:00
practicalswift 2c03be11b6 Unify log_to_file(...) and log_default_print(...) 2018-02-02 00:55:38 +00:00
practicalswift ebef98d8be Create log timestamp string from log entry data 2018-02-02 00:55:38 +00:00
practicalswift 3696e1b607 Usability: Prefix logging to stdout with ISO 8601 formatted date and time in UTC 2018-02-02 00:55:38 +00:00
Rusty Russell 327e2b8fd8 JSONRPC: listconfigs command.
With the new 'human-readable' mode of lightning-cli, this actually produces
a valid config file.  It's a bit hacky though...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 00:05:00 +01:00
Rusty Russell bd3480dc9c lightningd: remember --log-file arg.
And fclose old ones if we get handed it multiple times.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 00:05:00 +01:00
Rusty Russell ca2f72fd5f log: block reporting on minor memleak.
Exception: Node /tmp/lightning-t5gxc6gs/test_closing_different_fees/lightning-2/ has memory leaks: [{'value': '0x55caa0a0b8d0', 'label': 'ccan/ccan/tal/str/str.c:90:char[]', 'backtrace': ['ccan/ccan/tal/tal.c:467 (tal_alloc_)', 'ccan/ccan/tal/tal.c:496 (tal_alloc_arr_)', 'ccan/ccan/tal/str/str.c:90 (tal_vfmt)', 'lightningd/log.c:131 (new_log)', 'lightningd/subd.c:632 (new_subd)', 'lightningd/subd.c:686 (new_peer_subd)', 'lightningd/peer_control.c:2487 (peer_accept_channel)', 'lightningd/peer_control.c:674 (peer_sent_nongossip)', 'lightningd/gossip_control.c:55 (peer_nongossip)', 'lightningd/gossip_control.c:142 (gossip_msg)', 'lightningd/subd.c:477 (sd_msg_read)', 'lightningd/subd.c:319 (read_fds)', 'ccan/ccan/io/io.c:59 (next_plan)', 'ccan/ccan/io/io.c:387 (do_plan)', 'ccan/ccan/io/io.c:397 (io_ready)', 'ccan/ccan/io/poll.c:305 (io_loop)', 'lightningd/lightningd.c:347 (main)', '(null):0 ((null))', '(null):0 ((null))', '(null):0 ((null))'], 'parents': ['lightningd/log.c:103:struct log_book', 'lightningd/lightningd.c:43:struct lightningd']}]

Technically, true, but we save more memory by sharing the prefix pointer
than we lose by leaking it.

However, we'd ideally refcount so it's freed if the log is freed and
all the entries using it are pruned from the log book.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-30 19:47:27 +00:00
Rusty Russell 4957921e02 log: mark ltmp as notleak.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:43:10 +01:00
Rusty Russell dfc132b2fe memleak: add backtrace to allocations.
We use the tal notifiers to attach a `backtrace` object on every
allocation.

This also means moving backtrace_state from log.c into lightningd.c, so
we can hand it to memleak_init().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:43:10 +01:00
practicalswift 61c47c09d0 Fix typos 2017-12-08 13:07:20 +01:00
Rusty Russell bc9918ad46 dev: option not to do backtracing.
It crashes under valgrind, causing a valgrind error: valgrind gives us a
backtrace anyway, so we don't need it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 04:14:33 +00:00
Rusty Russell 21305c0d28 fatal: cause a backtrace.
Much nicer for debugging.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 04:14:33 +00:00
Rusty Russell 3404c393b7 common/io_debug: replacement for ccan/io's poll which does sanity checks.
For now we just check for outstanding take() or tal_tmpctx().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-29 10:20:08 +09:30
Rusty Russell db19873ee4 lightningd: dump backtrace on crash or fatal().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell be90364f7f log: remove struct helpers.
They predated (and inspired) type_to_string(), which is more general.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Rusty Russell afabbe0cb0 log: add ltmp convenience context.
It's sometimes nicer where you don't have a convenient tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Rusty Russell 8375857116 common: absorb remaining files from daemon/
Also, we split the more sophisticated json_add helpers to avoid pulling in
everything into lightning-cli, and unify the routines to print struct
short_channel_id (it's ':',  not '/' too).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-29 17:54:14 +02:00