Skip to content

Commit 673ae85

Browse files
plugin-bcli: revert the changes
Changelog-None Signed-off-by: Nishant Bansal <[email protected]>
1 parent 2bf03cb commit 673ae85

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

lightningd/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,4 +1178,4 @@ static const struct json_command getlog_command = {
11781178
"getlog",
11791179
json_getlog,
11801180
};
1181-
AUTODATA(json_command, &getlog_command);
1181+
AUTODATA(json_command, &getlog_command);

plugins/bcli.c

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ static const char **gather_argsv(const tal_t *ctx, const char *cmd, va_list ap)
130130
// system processes.
131131
add_arg(&args, "-stdinrpcpass");
132132

133-
134133
add_arg(&args, cmd);
135134
while ((arg = va_arg(ap, char *)) != NULL)
136135
add_arg(&args, arg);
@@ -1042,46 +1041,50 @@ static void wait_and_check_bitcoind(struct plugin *p)
10421041
const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
10431042
char *output = NULL;
10441043

1045-
plugin_log(p, LOG_UNUSUAL, "Waiting for bitcoind to warm up...");
1044+
for (;;) {
1045+
tal_free(output);
10461046

1047-
child = pipecmdarr(&in, &from, &from, cast_const2(char **, cmd));
1047+
child = pipecmdarr(&in, &from, &from, cast_const2(char **, cmd));
10481048

1049-
if (bitcoind->rpcpass)
1050-
write_all(in, bitcoind->rpcpass, strlen(bitcoind->rpcpass));
1049+
if (bitcoind->rpcpass)
1050+
write_all(in, bitcoind->rpcpass, strlen(bitcoind->rpcpass));
10511051

1052-
close(in);
1052+
close(in);
10531053

1054-
if (child < 0) {
1055-
if (errno == ENOENT)
1056-
bitcoind_failure(
1057-
p,
1058-
"bitcoin-cli not found. Is bitcoin-cli "
1059-
"(part of Bitcoin Core) available in your PATH?");
1060-
plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
1061-
}
1054+
if (child < 0) {
1055+
if (errno == ENOENT)
1056+
bitcoind_failure(p, "bitcoin-cli not found. Is bitcoin-cli "
1057+
"(part of Bitcoin Core) available in your PATH?");
1058+
plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
1059+
}
10621060

1063-
output = grab_fd(cmd, from);
1061+
output = grab_fd(cmd, from);
1062+
1063+
while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR);
1064+
if (ret != child)
1065+
bitcoind_failure(p, tal_fmt(bitcoind, "Waiting for %s: %s",
1066+
cmd[0], strerror(errno)));
1067+
if (!WIFEXITED(status))
1068+
bitcoind_failure(p, tal_fmt(bitcoind, "Death of %s: signal %i",
1069+
cmd[0], WTERMSIG(status)));
1070+
1071+
if (WEXITSTATUS(status) == 0)
1072+
break;
1073+
1074+
/* bitcoin/src/rpc/protocol.h:
1075+
* RPC_IN_WARMUP = -28, //!< Client still warming up
1076+
*/
1077+
if (WEXITSTATUS(status) != 28) {
1078+
if (WEXITSTATUS(status) == 1)
1079+
bitcoind_failure(p, "Could not connect to bitcoind using"
1080+
" bitcoin-cli. Is bitcoind running?");
1081+
bitcoind_failure(p, tal_fmt(bitcoind, "%s exited with code %i: %s",
1082+
cmd[0], WEXITSTATUS(status), output));
1083+
}
10641084

1065-
while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR)
1066-
;
1067-
if (ret != child)
1068-
bitcoind_failure(p, tal_fmt(bitcoind, "Waiting for %s: %s",
1069-
cmd[0], strerror(errno)));
1070-
if (!WIFEXITED(status))
1071-
bitcoind_failure(p, tal_fmt(bitcoind, "Death of %s: signal %i",
1072-
cmd[0], WTERMSIG(status)));
1073-
1074-
/* bitcoin/src/rpc/protocol.h:
1075-
* RPC_IN_WARMUP = -28, //!< Client still warming up
1076-
*/
1077-
if (WEXITSTATUS(status) != 28) {
1078-
if (WEXITSTATUS(status) == 1)
1079-
bitcoind_failure(p,
1080-
"Could not connect to bitcoind using"
1081-
" bitcoin-cli. Is bitcoind running?");
1082-
bitcoind_failure(p,
1083-
tal_fmt(bitcoind, "%s exited with code %i: %s",
1084-
cmd[0], WEXITSTATUS(status), output));
1085+
plugin_log(p, LOG_UNUSUAL,
1086+
"Waiting for bitcoind to warm up...");
1087+
sleep(1);
10851088
}
10861089

10871090
parse_getnetworkinfo_result(p, output);

0 commit comments

Comments
 (0)