mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
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:
parent
6f8754a72b
commit
578b297d46
@ -1,3 +1,3 @@
|
|||||||
CCAN imported from http://ccodearchive.net.
|
CCAN imported from http://ccodearchive.net.
|
||||||
|
|
||||||
CCAN version: init-2586-gd4932820
|
CCAN version: init-2587-gf927e4be
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
#include <ccan/io/io_plan.h>
|
#include <ccan/io/io_plan.h>
|
||||||
#include <errno.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)
|
static int do_fd_send(int fd, struct io_plan_arg *arg)
|
||||||
{
|
{
|
||||||
if (!fdpass_send(fd, arg->u1.s)) {
|
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 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (arg->u2.s)
|
if (arg->u2.vp) {
|
||||||
|
struct io_conn *conn = arg->u2.vp;
|
||||||
close(arg->u1.s);
|
close(arg->u1.s);
|
||||||
|
tal_del_destructor2(conn, destroy_conn_close_send_fd, arg);
|
||||||
|
}
|
||||||
return 1;
|
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);
|
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
|
||||||
|
|
||||||
arg->u1.s = fd;
|
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);
|
return io_set_plan(conn, IO_OUT, do_fd_send, next, next_arg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user