MCPcopy Create free account
hub / github.com/ElementsProject/lightning / new_subd

Function new_subd

lightningd/subd.c:694–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

692}
693
694static 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 }

Callers 2

new_global_subdFunction · 0.70
new_channel_subd_Function · 0.70

Calls 8

tal_freeFunction · 0.85
msg_queue_newFunction · 0.85
list_head_initFunction · 0.85
new_logFunction · 0.70
log_prefixFunction · 0.70
subdaemon_pathFunction · 0.70
subdFunction · 0.70
log_print_levelFunction · 0.70

Tested by

no test coverage detected