| 692 | } |
| 693 | |
| 694 | static struct subd *new_subd(const tal_t *ctx, |
| 695 | struct lightningd *ld, |
| 696 | const char *name, |
| 697 | void *channel, |
| 698 | const struct node_id *node_id, |
| 699 | struct log *base_log, |
| 700 | bool talks_to_peer, |
| 701 | const char *(*msgname)(int msgtype), |
| 702 | unsigned int (*msgcb)(struct subd *, |
| 703 | const u8 *, const int *fds), |
| 704 | void (*errcb)(void *channel, |
| 705 | struct peer_fd *peer_fd, |
| 706 | const struct channel_id *channel_id, |
| 707 | const char *desc, |
| 708 | bool warning, |
| 709 | const u8 *err_for_them), |
| 710 | void (*billboardcb)(void *channel, |
| 711 | bool perm, |
| 712 | const char *happenings), |
| 713 | va_list *ap) |
| 714 | { |
| 715 | struct subd *sd = tal(ctx, struct subd); |
| 716 | int msg_fd; |
| 717 | const char *debug_subd = NULL; |
| 718 | const char *shortname; |
| 719 | |
| 720 | assert(name != NULL); |
| 721 | |
| 722 | /* This part of the name is a bit redundant for logging */ |
| 723 | if (strstarts(name, "lightning_")) |
| 724 | shortname = name + strlen("lightning_"); |
| 725 | else |
| 726 | shortname = name; |
| 727 | |
| 728 | if (base_log) { |
| 729 | sd->log = new_log(sd, ld->log_book, node_id, |
| 730 | "%s-%s", shortname, log_prefix(base_log)); |
| 731 | } else { |
| 732 | sd->log = new_log(sd, ld->log_book, node_id, "%s", shortname); |
| 733 | } |
| 734 | |
| 735 | #if DEVELOPER |
| 736 | debug_subd = ld->dev_debug_subprocess; |
| 737 | #endif /* DEVELOPER */ |
| 738 | |
| 739 | const char *path = subdaemon_path(tmpctx, ld, name); |
| 740 | |
| 741 | sd->pid = subd(path, name, debug_subd, |
| 742 | &msg_fd, |
| 743 | /* We only turn on subdaemon io logging if we're going |
| 744 | * to print it: too stressful otherwise! */ |
| 745 | log_print_level(sd->log, node_id) < LOG_DBG, |
| 746 | ap); |
| 747 | if (sd->pid == (pid_t)-1) { |
| 748 | log_unusual(ld->log, "subd %s failed: %s", |
| 749 | name, strerror(errno)); |
| 750 | return tal_free(sd); |
| 751 | } |
no test coverage detected