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

Function destroy_subd

lightningd/subd.c:595–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593
594
595static void destroy_subd(struct subd *sd)
596{
597 int status;
598 bool fail_if_subd_fails;
599
600 fail_if_subd_fails = sd->ld->dev_subdaemon_fail;
601 list_del_from(&sd->ld->subds, &sd->list);
602
603 /* lightningd may have already done waitpid() */
604 if (sd->wstatus != NULL) {
605 status = *sd->wstatus;
606 } else {
607 switch (waitpid(sd->pid, &status, WNOHANG)) {
608 case 0:
609 /* If it's an essential daemon, don't kill: we want the
610 * exit status */
611 if (!sd->must_not_exit) {
612 log_debug(sd->log,
613 "Status closed, but not exited. Killing");
614 kill(sd->pid, SIGKILL);
615 }
616 waitpid(sd->pid, &status, 0);
617 fail_if_subd_fails = false;
618 break;
619 case -1:
620 log_broken(sd->log, "Status closed, but waitpid %i says %s",
621 sd->pid, strerror(errno));
622 status = -1;
623 break;
624 }
625 }
626
627 if (fail_if_subd_fails && WIFSIGNALED(status)) {
628 log_broken(sd->log, "Subdaemon %s killed with signal %i",
629 sd->name, WTERMSIG(status));
630 exit(1);
631 }
632
633 /* In case we're freed manually, such as channel_fail_permanent */
634 if (sd->conn)
635 sd->conn = tal_free(sd->conn);
636
637 /* Peer still attached? */
638 if (sd->channel) {
639 /* Don't loop back when we fail it. */
640 void *channel = sd->channel;
641 struct db *db = sd->ld->wallet->db;
642 bool outer_transaction;
643
644 /* Clear any transient messages in billboard */
645 sd->billboardcb(channel, false, NULL);
646 /* While it's cleaning up, this is not a leak! */
647 notleak(sd);
648 sd->channel = NULL;
649
650 /* We can be freed both inside msg handling, or spontaneously. */
651 outer_transaction = db_in_transaction(db);
652 if (!outer_transaction)

Callers 1

subd_shutdownFunction · 0.85

Calls 5

list_del_fromFunction · 0.85
tal_freeFunction · 0.85
errxFunction · 0.85
db_in_transactionFunction · 0.50
db_commit_transactionFunction · 0.50

Tested by

no test coverage detected