| 706 | } |
| 707 | |
| 708 | static struct subd *new_subd(const tal_t *ctx, |
| 709 | struct lightningd *ld, |
| 710 | const char *name, |
| 711 | void *channel, |
| 712 | const struct node_id *node_id, |
| 713 | struct logger *base_log, |
| 714 | bool talks_to_peer, |
| 715 | const char *(*msgname)(int msgtype), |
| 716 | unsigned int (*msgcb)(struct subd *, |
| 717 | const u8 *, const int *fds), |
| 718 | void (*errcb)(void *channel, |
| 719 | struct peer_fd *peer_fd, |
| 720 | const char *desc, |
| 721 | const u8 *err_for_them, |
| 722 | bool disconnect, |
| 723 | bool warning), |
| 724 | void (*billboardcb)(void *channel, |
| 725 | bool perm, |
| 726 | const char *happenings), |
| 727 | va_list *ap) |
| 728 | { |
| 729 | struct subd *sd = tal(ctx, struct subd); |
| 730 | int msg_fd; |
| 731 | const char *shortname; |
| 732 | |
| 733 | assert(name != NULL); |
| 734 | |
| 735 | /* This part of the name is a bit redundant for logging */ |
| 736 | if (strstarts(name, "lightning_")) |
| 737 | shortname = name + strlen("lightning_"); |
| 738 | else |
| 739 | shortname = name; |
| 740 | |
| 741 | if (base_log) { |
| 742 | sd->log = new_logger(sd, ld->log_book, node_id, |
| 743 | "%s-%s", shortname, log_prefix(base_log)); |
| 744 | } else { |
| 745 | sd->log = new_logger(sd, ld->log_book, node_id, "%s", shortname); |
| 746 | } |
| 747 | |
| 748 | const char *path = subdaemon_path(tmpctx, ld, name); |
| 749 | |
| 750 | sd->pid = subd(path, name, debugging(ld, name), |
| 751 | &msg_fd, |
| 752 | /* We only turn on subdaemon io/trace logging if we're going |
| 753 | * to print it: too stressful otherwise! */ |
| 754 | log_has_io_logging(sd->log), |
| 755 | log_has_trace_logging(sd->log), |
| 756 | ld->developer, |
| 757 | ap); |
| 758 | if (sd->pid == (pid_t)-1) { |
| 759 | log_unusual(ld->log, "subd %s failed: %s", |
| 760 | name, strerror(errno)); |
| 761 | return tal_free(sd); |
| 762 | } |
| 763 | sd->ld = ld; |
| 764 | |
| 765 | sd->name = shortname; |
no test coverage detected