| 254 | } |
| 255 | |
| 256 | static struct command_result *json_memleak(struct command *cmd, |
| 257 | const char *buffer, |
| 258 | const jsmntok_t *obj UNNEEDED, |
| 259 | const jsmntok_t *params) |
| 260 | { |
| 261 | struct lightningd *ld = cmd->ld; |
| 262 | u8 *msg; |
| 263 | bool found_leak; |
| 264 | struct leak_detect *leaks; |
| 265 | |
| 266 | if (!param(cmd, buffer, params, NULL)) |
| 267 | return command_param_failed(); |
| 268 | |
| 269 | if (!getenv("LIGHTNINGD_DEV_MEMLEAK")) { |
| 270 | return command_fail(cmd, LIGHTNINGD, |
| 271 | "Leak detection needs $LIGHTNINGD_DEV_MEMLEAK"); |
| 272 | } |
| 273 | |
| 274 | leaks = tal(cmd, struct leak_detect); |
| 275 | leaks->cmd = cmd; |
| 276 | leaks->num_outstanding_requests = 0; |
| 277 | leaks->leakers = tal_arr(leaks, const char *, 0); |
| 278 | |
| 279 | /* hsmd is sync, so do that first. */ |
| 280 | if (!wire_sync_write(ld->hsm_fd, |
| 281 | take(towire_hsmd_dev_memleak(NULL)))) |
| 282 | fatal("Could not write to HSM: %s", strerror(errno)); |
| 283 | msg = wire_sync_read(tmpctx, ld->hsm_fd); |
| 284 | if (!fromwire_hsmd_dev_memleak_reply(msg, &found_leak)) |
| 285 | fatal("Bad HSMD_DEV_MEMLEAK_REPLY: %s", tal_hex(tmpctx, msg)); |
| 286 | |
| 287 | if (found_leak) |
| 288 | report_subd_memleak(leaks, ld->hsm); |
| 289 | |
| 290 | /* Now do all the async ones. */ |
| 291 | start_leak_request(subd_req(ld->connectd, ld->connectd, |
| 292 | take(towire_connectd_dev_memleak(NULL)), |
| 293 | -1, 0, connect_dev_memleak_done, leaks), |
| 294 | leaks); |
| 295 | start_leak_request(subd_req(ld->gossip, ld->gossip, |
| 296 | take(towire_gossipd_dev_memleak(NULL)), |
| 297 | -1, 0, gossip_dev_memleak_done, leaks), |
| 298 | leaks); |
| 299 | |
| 300 | /* Ask all per-peer daemons */ |
| 301 | peer_dev_memleak(ld, leaks); |
| 302 | |
| 303 | /* Set timer: dualopend doesn't always listen! */ |
| 304 | notleak(new_reltimer(ld->timers, leaks, time_from_sec(20), |
| 305 | leak_detect_timeout, leaks)); |
| 306 | return command_still_pending(cmd); |
| 307 | } |
| 308 | |
| 309 | static const struct json_command dev_memleak_command = { |
| 310 | "dev-memleak", |
nothing calls this directly
no test coverage detected