mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-26 01:04:20 +01:00
lightningd: enable io logging on subdaemons iff we're going to print it.
This simplifies our tests, too, since we don't need a magic option to enable io logging in subdaemons. Note that test_bad_onion still takes too long, due to a separate minor bug, so that's marked and left dev-only for now. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -137,7 +137,9 @@ static void close_taken_fds(va_list *ap)
|
||||
/* We use sockets, not pipes, because fds are bidir. */
|
||||
static int subd(const char *dir, const char *name,
|
||||
const char *debug_subdaemon,
|
||||
int *msgfd, int dev_disconnect_fd, va_list *ap)
|
||||
int *msgfd, int dev_disconnect_fd,
|
||||
bool io_logging,
|
||||
va_list *ap)
|
||||
{
|
||||
int childmsg[2], execfail[2];
|
||||
pid_t childpid;
|
||||
@@ -161,7 +163,7 @@ static int subd(const char *dir, const char *name,
|
||||
int fdnum = 3, i, stdin_is_now = STDIN_FILENO;
|
||||
long max;
|
||||
size_t num_args;
|
||||
char *args[] = { NULL, NULL, NULL, NULL };
|
||||
char *args[] = { NULL, NULL, NULL, NULL, NULL };
|
||||
|
||||
close(childmsg[0]);
|
||||
close(execfail[0]);
|
||||
@@ -200,6 +202,8 @@ static int subd(const char *dir, const char *name,
|
||||
|
||||
num_args = 0;
|
||||
args[num_args++] = path_join(NULL, dir, name);
|
||||
if (io_logging)
|
||||
args[num_args++] = "--log-io";
|
||||
#if DEVELOPER
|
||||
if (dev_disconnect_fd != -1)
|
||||
args[num_args++] = tal_fmt(NULL, "--dev-disconnect=%i", dev_disconnect_fd);
|
||||
@@ -622,33 +626,42 @@ static struct subd *new_subd(struct lightningd *ld,
|
||||
int msg_fd;
|
||||
const char *debug_subd = NULL;
|
||||
int disconnect_fd = -1;
|
||||
const char *shortname;
|
||||
|
||||
assert(name != NULL);
|
||||
|
||||
/* This part of the name is a bit redundant for logging */
|
||||
if (strstarts(name, "lightning_"))
|
||||
shortname = name + strlen("lightning_");
|
||||
else
|
||||
shortname = name;
|
||||
|
||||
if (base_log) {
|
||||
sd->log = new_log(sd, ld->log_book, node_id,
|
||||
"%s-%s", shortname, log_prefix(base_log));
|
||||
} else {
|
||||
sd->log = new_log(sd, ld->log_book, node_id, "%s", shortname);
|
||||
}
|
||||
|
||||
#if DEVELOPER
|
||||
debug_subd = ld->dev_debug_subprocess;
|
||||
disconnect_fd = ld->dev_disconnect_fd;
|
||||
#endif /* DEVELOPER */
|
||||
|
||||
sd->pid = subd(ld->daemon_dir, name, debug_subd,
|
||||
&msg_fd, disconnect_fd, ap);
|
||||
&msg_fd, disconnect_fd,
|
||||
/* We only turn on subdaemon io logging if we're going
|
||||
* to print it: too stressful otherwise! */
|
||||
log_print_level(sd->log) < LOG_DBG,
|
||||
ap);
|
||||
if (sd->pid == (pid_t)-1) {
|
||||
log_unusual(ld->log, "subd %s failed: %s",
|
||||
name, strerror(errno));
|
||||
return tal_free(sd);
|
||||
}
|
||||
sd->ld = ld;
|
||||
/* This part of the name is a bit redundant for logging */
|
||||
if (strstarts(name, "lightning_"))
|
||||
name += strlen("lightning_");
|
||||
if (base_log) {
|
||||
sd->log = new_log(sd, ld->log_book, node_id,
|
||||
"%s-%s", name, log_prefix(base_log));
|
||||
} else {
|
||||
sd->log = new_log(sd, ld->log_book, node_id, "%s", name);
|
||||
}
|
||||
|
||||
sd->name = name;
|
||||
sd->name = shortname;
|
||||
sd->must_not_exit = false;
|
||||
sd->talks_to_peer = talks_to_peer;
|
||||
sd->msgname = msgname;
|
||||
|
||||
@@ -124,6 +124,9 @@ void log_backtrace_print(const char *fmt UNNEEDED, ...)
|
||||
/* Generated stub for log_prefix */
|
||||
const char *log_prefix(const struct log *log UNNEEDED)
|
||||
{ fprintf(stderr, "log_prefix called!\n"); abort(); }
|
||||
/* Generated stub for log_print_level */
|
||||
enum log_level log_print_level(struct log *log UNNEEDED)
|
||||
{ fprintf(stderr, "log_print_level called!\n"); abort(); }
|
||||
/* Generated stub for log_status_msg */
|
||||
bool log_status_msg(struct log *log UNNEEDED,
|
||||
const struct node_id *node_id UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user