ccan: update to get fdpass fix.

Theoretical only, but we could leak an fd if we closed a conn before
the fd was sent.  This doesn't happen in our current codebase because
we only hand fds to connectd, which only closes at shutdown.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-07-09 11:22:40 +09:30
parent 6f8754a72b
commit 578b297d46
2 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,3 @@
CCAN imported from http://ccodearchive.net.
CCAN version: init-2586-gd4932820
CCAN version: init-2587-gf927e4be

View File

@ -4,6 +4,12 @@
#include <ccan/io/io_plan.h>
#include <errno.h>
static void destroy_conn_close_send_fd(struct io_conn *conn,
struct io_plan_arg *arg)
{
close(arg->u1.s);
}
static int do_fd_send(int fd, struct io_plan_arg *arg)
{
if (!fdpass_send(fd, arg->u1.s)) {
@ -12,8 +18,11 @@ static int do_fd_send(int fd, struct io_plan_arg *arg)
return 0;
return -1;
}
if (arg->u2.s)
if (arg->u2.vp) {
struct io_conn *conn = arg->u2.vp;
close(arg->u1.s);
tal_del_destructor2(conn, destroy_conn_close_send_fd, arg);
}
return 1;
}
@ -26,7 +35,11 @@ struct io_plan *io_send_fd_(struct io_conn *conn,
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
arg->u1.s = fd;
arg->u2.s = fdclose;
/* We need conn ptr for destructor */
arg->u2.vp = fdclose ? conn : NULL;
/* If conn closes before sending, we still need to close fd */
if (fdclose)
tal_add_destructor2(conn, destroy_conn_close_send_fd, arg);
return io_set_plan(conn, IO_OUT, do_fd_send, next, next_arg);
}