Browse Source

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

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
a600b1a30f
  1. 5
      lightningd/handshake/handshake.c
  2. 14
      lightningd/peer_control.c

5
lightningd/handshake/handshake.c

@ -965,12 +965,12 @@ static void responder(int fd,
} }
#ifndef TESTING #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[]) int main(int argc, char *argv[])
{ {
u8 *msg; u8 *msg;
struct pubkey my_id, their_id; struct pubkey my_id, their_id;
int hsmfd = 3, clientfd; int hsmfd = 3, clientfd = 4;
struct secret ck, rk, sk; struct secret ck, rk, sk;
struct crypto_state *cs; struct crypto_state *cs;
@ -989,7 +989,6 @@ int main(int argc, char *argv[])
msg = wire_sync_read(NULL, REQ_FD); msg = wire_sync_read(NULL, REQ_FD);
if (!msg) if (!msg)
status_failed(WIRE_BAD_COMMAND, "%s", strerror(errno)); status_failed(WIRE_BAD_COMMAND, "%s", strerror(errno));
clientfd = fdpass_recv(REQ_FD);
if (clientfd < 0) if (clientfd < 0)
status_failed(WIRE_BAD_FDPASS, "%s", strerror(errno)); status_failed(WIRE_BAD_FDPASS, "%s", strerror(errno));

14
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_status_wire_type_name,
handshake_control_wire_type_name, handshake_control_wire_type_name,
NULL, NULL, NULL, NULL,
peer->hsmfd, -1); peer->hsmfd, peer->fd, -1);
if (!peer->owner) { if (!peer->owner) {
log_unusual(peer->ld->log, "Could not subdaemon handshake: %s", log_unusual(peer->ld->log, "Could not subdaemon handshake: %s",
strerror(errno)); strerror(errno));
@ -155,6 +155,9 @@ static void peer_got_hsmfd(struct subdaemon *hsm, const u8 *msg,
goto error; goto error;
} }
/* Peer struct longer owns fd. */
peer->fd = -1;
/* Now handshake owns peer: until it succeeds, peer vanishes /* Now handshake owns peer: until it succeeds, peer vanishes
* when it does. */ * when it does. */
tal_steal(peer->owner, peer); 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"); peer_set_condition(peer, "Starting handshake as responder");
} }
/* Now hand peer fd to the handshake daemon, it hand back on success */ /* Now hand peer request to the handshake daemon: hands it
subdaemon_req(peer->owner, take(req), * back on success */
peer->fd, &peer->fd, subdaemon_req(peer->owner, take(req), -1, &peer->fd,
handshake_succeeded, peer); handshake_succeeded, peer);
/* Peer struct longer owns fd. */
peer->fd = -1;
return; return;
error: error:

Loading…
Cancel
Save