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

Function wait_and_check_bitcoind

plugins/bcli.c:862–922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

860}
861
862static void wait_and_check_bitcoind(struct plugin *p)
863{
864 int in, from, status, ret;
865 pid_t child;
866 const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
867 bool printed = false;
868 char *output = NULL;
869
870 for (;;) {
871 tal_free(output);
872
873 child = pipecmdarr(&in, &from, &from, cast_const2(char **, cmd));
874
875 if (bitcoind->rpcpass)
876 write_all(in, bitcoind->rpcpass, strlen(bitcoind->rpcpass));
877
878 close(in);
879
880 if (child < 0) {
881 if (errno == ENOENT)
882 bitcoind_failure(p, "bitcoin-cli not found. Is bitcoin-cli "
883 "(part of Bitcoin Core) available in your PATH?");
884 plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
885 }
886
887 output = grab_fd(cmd, from);
888
889 while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR);
890 if (ret != child)
891 bitcoind_failure(p, tal_fmt(bitcoind, "Waiting for %s: %s",
892 cmd[0], strerror(errno)));
893 if (!WIFEXITED(status))
894 bitcoind_failure(p, tal_fmt(bitcoind, "Death of %s: signal %i",
895 cmd[0], WTERMSIG(status)));
896
897 if (WEXITSTATUS(status) == 0)
898 break;
899
900 /* bitcoin/src/rpc/protocol.h:
901 * RPC_IN_WARMUP = -28, //!< Client still warming up
902 */
903 if (WEXITSTATUS(status) != 28) {
904 if (WEXITSTATUS(status) == 1)
905 bitcoind_failure(p, "Could not connect to bitcoind using"
906 " bitcoin-cli. Is bitcoind running?");
907 bitcoind_failure(p, tal_fmt(bitcoind, "%s exited with code %i: %s",
908 cmd[0], WEXITSTATUS(status), output));
909 }
910
911 if (!printed) {
912 plugin_log(p, LOG_UNUSUAL,
913 "Waiting for bitcoind to warm up...");
914 printed = true;
915 }
916 sleep(1);
917 }
918
919 parse_getnetworkinfo_result(p, output);

Callers 1

initFunction · 0.85

Calls 9

tal_freeFunction · 0.85
pipecmdarrFunction · 0.85
bitcoind_failureFunction · 0.85
grab_fdFunction · 0.85
gather_argsFunction · 0.70
plugin_errFunction · 0.70
plugin_logFunction · 0.70
write_allFunction · 0.50

Tested by

no test coverage detected