handshake: hand in client fd on exec instead of gratuitous fd passing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-02-02 14:35:45 +10:30
parent 13a30ff79c
commit a600b1a30f
2 changed files with 9 additions and 10 deletions

View File

@ -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));

View File

@ -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: