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 <joerg.vehlow@aox.de>
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;