From a600b1a30ff204717723a0d6c34da22afa9dc72d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Feb 2017 14:35:45 +1030 Subject: [PATCH] handshake: hand in client fd on exec instead of gratuitous fd passing. Signed-off-by: Rusty Russell --- lightningd/handshake/handshake.c | 5 ++--- lightningd/peer_control.c | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lightningd/handshake/handshake.c b/lightningd/handshake/handshake.c index 49798e1b7..3db6fc3ae 100644 --- a/lightningd/handshake/handshake.c +++ b/lightningd/handshake/handshake.c @@ -965,12 +965,12 @@ static void responder(int fd, } #ifndef TESTING -/* We expect hsmfd as fd 3, then a request then the clientfd */ +/* We expect hsmfd as fd 3, clientfd as 4 */ int main(int argc, char *argv[]) { u8 *msg; struct pubkey my_id, their_id; - int hsmfd = 3, clientfd; + int hsmfd = 3, clientfd = 4; struct secret ck, rk, sk; struct crypto_state *cs; @@ -989,7 +989,6 @@ int main(int argc, char *argv[]) msg = wire_sync_read(NULL, REQ_FD); if (!msg) status_failed(WIRE_BAD_COMMAND, "%s", strerror(errno)); - clientfd = fdpass_recv(REQ_FD); if (clientfd < 0) status_failed(WIRE_BAD_FDPASS, "%s", strerror(errno)); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4949a234e..481b46d9e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -147,7 +147,7 @@ static void peer_got_hsmfd(struct subdaemon *hsm, const u8 *msg, handshake_status_wire_type_name, handshake_control_wire_type_name, NULL, NULL, - peer->hsmfd, -1); + peer->hsmfd, peer->fd, -1); if (!peer->owner) { log_unusual(peer->ld->log, "Could not subdaemon handshake: %s", strerror(errno)); @@ -155,6 +155,9 @@ static void peer_got_hsmfd(struct subdaemon *hsm, const u8 *msg, goto error; } + /* Peer struct longer owns fd. */ + peer->fd = -1; + /* Now handshake owns peer: until it succeeds, peer vanishes * when it does. */ tal_steal(peer->owner, peer); @@ -168,13 +171,10 @@ static void peer_got_hsmfd(struct subdaemon *hsm, const u8 *msg, peer_set_condition(peer, "Starting handshake as responder"); } - /* Now hand peer fd to the handshake daemon, it hand back on success */ - subdaemon_req(peer->owner, take(req), - peer->fd, &peer->fd, + /* Now hand peer request to the handshake daemon: hands it + * back on success */ + subdaemon_req(peer->owner, take(req), -1, &peer->fd, handshake_succeeded, peer); - - /* Peer struct longer owns fd. */ - peer->fd = -1; return; error: