From: Joerg Vehlow Date: Wed, 26 Oct 2022 08:21:04 +0000 (+0200) Subject: libnl-tiny: set SOCK_CLOEXEC if available X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=db3b2cdbca5277723326a2720024a59fb821ae36;p=project%2Flibnl-tiny.git 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 --- 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;