~ This is used by the master to create a new client connection (which * becomes the HSM_FD for the subdaemon after forking). */
| 517 | /*~ This is used by the master to create a new client connection (which |
| 518 | * becomes the HSM_FD for the subdaemon after forking). */ |
| 519 | static struct io_plan *pass_client_hsmfd(struct io_conn *conn, |
| 520 | struct client *c, |
| 521 | const u8 *msg_in) |
| 522 | { |
| 523 | int fds[2]; |
| 524 | u64 dbid, capabilities; |
| 525 | struct node_id id; |
| 526 | |
| 527 | /* This must be lightningd itself. */ |
| 528 | assert(is_lightningd(c)); |
| 529 | |
| 530 | if (!fromwire_hsmd_client_hsmfd(msg_in, &id, &dbid, &capabilities)) |
| 531 | return bad_req(conn, c, msg_in); |
| 532 | |
| 533 | /* socketpair is a bi-directional pipe, which is what we want. */ |
| 534 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0) |
| 535 | status_failed(STATUS_FAIL_INTERNAL_ERROR, "creating fds: %s", |
| 536 | strerror(errno)); |
| 537 | |
| 538 | status_debug("new_client: %"PRIu64, dbid); |
| 539 | new_client(c, c->chainparams, &id, dbid, capabilities, fds[0]); |
| 540 | |
| 541 | /*~ We stash this in a global, because we need to get both the fd and |
| 542 | * the client pointer to the callback. The other way would be to |
| 543 | * create a boutique structure and hand that, but we don't need to. */ |
| 544 | pending_client_fd = fds[1]; |
| 545 | return io_write_wire(conn, take(towire_hsmd_client_hsmfd_reply(NULL)), |
| 546 | send_pending_client_fd, c); |
| 547 | } |
| 548 | |
| 549 | #if DEVELOPER |
| 550 | static struct io_plan *handle_memleak(struct io_conn *conn, |
no test coverage detected