From db3b2cdbca5277723326a2720024a59fb821ae36 Mon Sep 17 00:00:00 2001 From: Joerg Vehlow Date: Wed, 26 Oct 2022 10:21:04 +0200 Subject: [PATCH] libnl-tiny: set SOCK_CLOEXEC if available If CLOEXEC is not set on the netlink socket, restarting netifd using ubus fails with "Failed to initialize system control", because the bind call in nl_connect fails with EADDRINUSE, due to the inherited socket handle. Also it does not make sense, to leak the handle to child processes. See libnl3: ca0fc7558 ("socket: Set SOCK_CLOEXEC if available") Signed-off-by: Joerg Vehlow --- nl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nl.c b/nl.c index c875573..32d26a3 100644 --- a/nl.c +++ b/nl.c @@ -106,9 +106,14 @@ int nl_connect(struct nl_sock *sk, int protocol) { int err; + int flags = 0; socklen_t addrlen; - sk->s_fd = socket(AF_NETLINK, SOCK_RAW, protocol); +#ifdef SOCK_CLOEXEC + flags = SOCK_CLOEXEC; +#endif + + sk->s_fd = socket(AF_NETLINK, SOCK_RAW | flags, protocol); if (sk->s_fd < 0) { err = -nl_syserr2nlerr(errno); goto errout; -- 2.30.2