mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
lightningd: make bcli_args() helper take ctx.
Otherwise we can get leak complaints: all callers now use tmpctx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2cdc5fb964
commit
9b8c8f652b
1 changed files with 37 additions and 27 deletions
|
@ -103,14 +103,14 @@ static struct io_plan *output_init(struct io_conn *conn, struct bitcoin_cli *bcl
|
||||||
static void next_bcli(struct bitcoind *bitcoind);
|
static void next_bcli(struct bitcoind *bitcoind);
|
||||||
|
|
||||||
/* For printing: simple string of args. */
|
/* For printing: simple string of args. */
|
||||||
static char *bcli_args(struct bitcoin_cli *bcli)
|
static char *bcli_args(const tal_t *ctx, struct bitcoin_cli *bcli)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char *ret = tal_strdup(bcli, bcli->args[0]);
|
char *ret = tal_strdup(ctx, bcli->args[0]);
|
||||||
|
|
||||||
for (i = 1; bcli->args[i]; i++) {
|
for (i = 1; bcli->args[i]; i++) {
|
||||||
ret = tal_strcat(bcli, take(ret), " ");
|
ret = tal_strcat(ctx, take(ret), " ");
|
||||||
ret = tal_strcat(bcli, take(ret), bcli->args[i]);
|
ret = tal_strcat(ctx, take(ret), bcli->args[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -134,14 +134,15 @@ static void bcli_failure(struct bitcoind *bitcoind,
|
||||||
t = timemono_between(time_mono(), bitcoind->first_error_time);
|
t = timemono_between(time_mono(), bitcoind->first_error_time);
|
||||||
if (time_greater(t, time_from_sec(60)))
|
if (time_greater(t, time_from_sec(60)))
|
||||||
fatal("%s exited %u (after %u other errors) '%.*s'",
|
fatal("%s exited %u (after %u other errors) '%.*s'",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
exitstatus,
|
exitstatus,
|
||||||
bitcoind->error_count,
|
bitcoind->error_count,
|
||||||
(int)bcli->output_bytes,
|
(int)bcli->output_bytes,
|
||||||
bcli->output);
|
bcli->output);
|
||||||
|
|
||||||
log_unusual(bitcoind->log,
|
log_unusual(bitcoind->log,
|
||||||
"%s exited with status %u", bcli_args(bcli), exitstatus);
|
"%s exited with status %u",
|
||||||
|
bcli_args(tmpctx, bcli), exitstatus);
|
||||||
|
|
||||||
bitcoind->error_count++;
|
bitcoind->error_count++;
|
||||||
|
|
||||||
|
@ -159,12 +160,12 @@ static void bcli_finished(struct io_conn *conn UNUSED, struct bitcoin_cli *bcli)
|
||||||
/* FIXME: If we waited for SIGCHILD, this could never hang! */
|
/* FIXME: If we waited for SIGCHILD, this could never hang! */
|
||||||
while ((ret = waitpid(bcli->pid, &status, 0)) < 0 && errno == EINTR);
|
while ((ret = waitpid(bcli->pid, &status, 0)) < 0 && errno == EINTR);
|
||||||
if (ret != bcli->pid)
|
if (ret != bcli->pid)
|
||||||
fatal("%s %s", bcli_args(bcli),
|
fatal("%s %s", bcli_args(tmpctx, bcli),
|
||||||
ret == 0 ? "not exited?" : strerror(errno));
|
ret == 0 ? "not exited?" : strerror(errno));
|
||||||
|
|
||||||
if (!WIFEXITED(status))
|
if (!WIFEXITED(status))
|
||||||
fatal("%s died with signal %i",
|
fatal("%s died with signal %i",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
WTERMSIG(status));
|
WTERMSIG(status));
|
||||||
|
|
||||||
if (!bcli->exitstatus) {
|
if (!bcli->exitstatus) {
|
||||||
|
@ -292,13 +293,13 @@ static bool extract_feerate(struct bitcoin_cli *bcli,
|
||||||
tokens = json_parse_input(output, output_bytes, &valid);
|
tokens = json_parse_input(output, output_bytes, &valid);
|
||||||
if (!tokens)
|
if (!tokens)
|
||||||
fatal("%s: %s response",
|
fatal("%s: %s response",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
valid ? "partial" : "invalid");
|
valid ? "partial" : "invalid");
|
||||||
|
|
||||||
if (tokens[0].type != JSMN_OBJECT) {
|
if (tokens[0].type != JSMN_OBJECT) {
|
||||||
log_unusual(bcli->bitcoind->log,
|
log_unusual(bcli->bitcoind->log,
|
||||||
"%s: gave non-object (%.*s)?",
|
"%s: gave non-object (%.*s)?",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
(int)output_bytes, output);
|
(int)output_bytes, output);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -418,7 +419,7 @@ static bool process_rawblock(struct bitcoin_cli *bcli)
|
||||||
blk = bitcoin_block_from_hex(bcli, bcli->output, bcli->output_bytes);
|
blk = bitcoin_block_from_hex(bcli, bcli->output, bcli->output_bytes);
|
||||||
if (!blk)
|
if (!blk)
|
||||||
fatal("%s: bad block '%.*s'?",
|
fatal("%s: bad block '%.*s'?",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
(int)bcli->output_bytes, bcli->output);
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
cb(bcli->bitcoind, blk, bcli->cb_arg);
|
cb(bcli->bitcoind, blk, bcli->cb_arg);
|
||||||
|
@ -452,7 +453,7 @@ static bool process_getblockcount(struct bitcoin_cli *bcli)
|
||||||
blockcount = strtol(p, &end, 10);
|
blockcount = strtol(p, &end, 10);
|
||||||
if (end == p || *end != '\n')
|
if (end == p || *end != '\n')
|
||||||
fatal("%s: gave non-numeric blockcount %s",
|
fatal("%s: gave non-numeric blockcount %s",
|
||||||
bcli_args(bcli), p);
|
bcli_args(tmpctx, bcli), p);
|
||||||
|
|
||||||
cb(bcli->bitcoind, blockcount, bcli->cb_arg);
|
cb(bcli->bitcoind, blockcount, bcli->cb_arg);
|
||||||
return true;
|
return true;
|
||||||
|
@ -498,7 +499,7 @@ static bool process_gettxout(struct bitcoin_cli *bcli)
|
||||||
string on a spent gettxout */
|
string on a spent gettxout */
|
||||||
if (*bcli->exitstatus != 0 || bcli->output_bytes == 0) {
|
if (*bcli->exitstatus != 0 || bcli->output_bytes == 0) {
|
||||||
log_debug(bcli->bitcoind->log, "%s: not unspent output?",
|
log_debug(bcli->bitcoind->log, "%s: not unspent output?",
|
||||||
bcli_args(bcli));
|
bcli_args(tmpctx, bcli));
|
||||||
cb(bcli->bitcoind, NULL, bcli->cb_arg);
|
cb(bcli->bitcoind, NULL, bcli->cb_arg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -506,35 +507,41 @@ static bool process_gettxout(struct bitcoin_cli *bcli)
|
||||||
tokens = json_parse_input(bcli->output, bcli->output_bytes, &valid);
|
tokens = json_parse_input(bcli->output, bcli->output_bytes, &valid);
|
||||||
if (!tokens)
|
if (!tokens)
|
||||||
fatal("%s: %s response",
|
fatal("%s: %s response",
|
||||||
bcli_args(bcli), valid ? "partial" : "invalid");
|
bcli_args(tmpctx, bcli), valid ? "partial" : "invalid");
|
||||||
|
|
||||||
if (tokens[0].type != JSMN_OBJECT)
|
if (tokens[0].type != JSMN_OBJECT)
|
||||||
fatal("%s: gave non-object (%.*s)?",
|
fatal("%s: gave non-object (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
valuetok = json_get_member(bcli->output, tokens, "value");
|
valuetok = json_get_member(bcli->output, tokens, "value");
|
||||||
if (!valuetok)
|
if (!valuetok)
|
||||||
fatal("%s: had no value member (%.*s)?",
|
fatal("%s: had no value member (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
if (!json_tok_bitcoin_amount(bcli->output, valuetok, &out.amount))
|
if (!json_tok_bitcoin_amount(bcli->output, valuetok, &out.amount))
|
||||||
fatal("%s: had bad value (%.*s)?",
|
fatal("%s: had bad value (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
scriptpubkeytok = json_get_member(bcli->output, tokens, "scriptPubKey");
|
scriptpubkeytok = json_get_member(bcli->output, tokens, "scriptPubKey");
|
||||||
if (!scriptpubkeytok)
|
if (!scriptpubkeytok)
|
||||||
fatal("%s: had no scriptPubKey member (%.*s)?",
|
fatal("%s: had no scriptPubKey member (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
hextok = json_get_member(bcli->output, scriptpubkeytok, "hex");
|
hextok = json_get_member(bcli->output, scriptpubkeytok, "hex");
|
||||||
if (!hextok)
|
if (!hextok)
|
||||||
fatal("%s: had no scriptPubKey->hex member (%.*s)?",
|
fatal("%s: had no scriptPubKey->hex member (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
out.script = tal_hexdata(bcli, bcli->output + hextok->start,
|
out.script = tal_hexdata(bcli, bcli->output + hextok->start,
|
||||||
hextok->end - hextok->start);
|
hextok->end - hextok->start);
|
||||||
if (!out.script)
|
if (!out.script)
|
||||||
fatal("%s: scriptPubKey->hex invalid hex (%.*s)?",
|
fatal("%s: scriptPubKey->hex invalid hex (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
cb(bcli->bitcoind, &out, bcli->cb_arg);
|
cb(bcli->bitcoind, &out, bcli->cb_arg);
|
||||||
return true;
|
return true;
|
||||||
|
@ -563,7 +570,7 @@ static bool process_getblock(struct bitcoin_cli *bcli)
|
||||||
* the callback with NULL to indicate failure */
|
* the callback with NULL to indicate failure */
|
||||||
log_debug(bcli->bitcoind->log,
|
log_debug(bcli->bitcoind->log,
|
||||||
"%s: returned invalid block, is this a pruned node?",
|
"%s: returned invalid block, is this a pruned node?",
|
||||||
bcli_args(bcli));
|
bcli_args(tmpctx, bcli));
|
||||||
cb(bcli->bitcoind, NULL, cbarg);
|
cb(bcli->bitcoind, NULL, cbarg);
|
||||||
tal_free(go);
|
tal_free(go);
|
||||||
return true;
|
return true;
|
||||||
|
@ -571,7 +578,8 @@ static bool process_getblock(struct bitcoin_cli *bcli)
|
||||||
|
|
||||||
if (tokens[0].type != JSMN_OBJECT)
|
if (tokens[0].type != JSMN_OBJECT)
|
||||||
fatal("%s: gave non-object (%.*s)?",
|
fatal("%s: gave non-object (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
/* "tx": [
|
/* "tx": [
|
||||||
"1a7bb0f58a5d235d232deb61d9e2208dabe69848883677abe78e9291a00638e8",
|
"1a7bb0f58a5d235d232deb61d9e2208dabe69848883677abe78e9291a00638e8",
|
||||||
|
@ -581,13 +589,14 @@ static bool process_getblock(struct bitcoin_cli *bcli)
|
||||||
txstok = json_get_member(bcli->output, tokens, "tx");
|
txstok = json_get_member(bcli->output, tokens, "tx");
|
||||||
if (!txstok)
|
if (!txstok)
|
||||||
fatal("%s: had no tx member (%.*s)?",
|
fatal("%s: had no tx member (%.*s)?",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
|
|
||||||
/* Now, this can certainly happen, if txnum too large. */
|
/* Now, this can certainly happen, if txnum too large. */
|
||||||
txidtok = json_get_arr(txstok, go->txnum);
|
txidtok = json_get_arr(txstok, go->txnum);
|
||||||
if (!txidtok) {
|
if (!txidtok) {
|
||||||
log_debug(bcli->bitcoind->log, "%s: no txnum %u",
|
log_debug(bcli->bitcoind->log, "%s: no txnum %u",
|
||||||
bcli_args(bcli), go->txnum);
|
bcli_args(tmpctx, bcli), go->txnum);
|
||||||
cb(bcli->bitcoind, NULL, cbarg);
|
cb(bcli->bitcoind, NULL, cbarg);
|
||||||
tal_free(go);
|
tal_free(go);
|
||||||
return true;
|
return true;
|
||||||
|
@ -597,7 +606,7 @@ static bool process_getblock(struct bitcoin_cli *bcli)
|
||||||
txidtok->end - txidtok->start,
|
txidtok->end - txidtok->start,
|
||||||
&txid))
|
&txid))
|
||||||
fatal("%s: had bad txid (%.*s)?",
|
fatal("%s: had bad txid (%.*s)?",
|
||||||
bcli_args(bcli),
|
bcli_args(tmpctx, bcli),
|
||||||
txidtok->end - txidtok->start,
|
txidtok->end - txidtok->start,
|
||||||
bcli->output + txidtok->start);
|
bcli->output + txidtok->start);
|
||||||
|
|
||||||
|
@ -618,7 +627,7 @@ static bool process_getblockhash_for_txout(struct bitcoin_cli *bcli)
|
||||||
if (*bcli->exitstatus != 0) {
|
if (*bcli->exitstatus != 0) {
|
||||||
void *cbarg = go->cbarg;
|
void *cbarg = go->cbarg;
|
||||||
log_debug(bcli->bitcoind->log, "%s: invalid blocknum?",
|
log_debug(bcli->bitcoind->log, "%s: invalid blocknum?",
|
||||||
bcli_args(bcli));
|
bcli_args(tmpctx, bcli));
|
||||||
tal_free(go);
|
tal_free(go);
|
||||||
cb(bcli->bitcoind, NULL, cbarg);
|
cb(bcli->bitcoind, NULL, cbarg);
|
||||||
return true;
|
return true;
|
||||||
|
@ -677,7 +686,8 @@ static bool process_getblockhash(struct bitcoin_cli *bcli)
|
||||||
|| !bitcoin_blkid_from_hex(bcli->output, bcli->output_bytes-1,
|
|| !bitcoin_blkid_from_hex(bcli->output, bcli->output_bytes-1,
|
||||||
&blkid)) {
|
&blkid)) {
|
||||||
fatal("%s: bad blockid '%.*s'",
|
fatal("%s: bad blockid '%.*s'",
|
||||||
bcli_args(bcli), (int)bcli->output_bytes, bcli->output);
|
bcli_args(tmpctx, bcli),
|
||||||
|
(int)bcli->output_bytes, bcli->output);
|
||||||
}
|
}
|
||||||
|
|
||||||
cb(bcli->bitcoind, &blkid, bcli->cb_arg);
|
cb(bcli->bitcoind, &blkid, bcli->cb_arg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue