[libiwinfo] apply FD_CLOEXEC on internal ioctl and netlink sockets
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_nl80211.c
index a643efb..49ddf13 100644 (file)
@@ -32,7 +32,7 @@ static struct nl80211_state *nls = NULL;
 
 static int nl80211_init(void)
 {
-       int err;
+       int err, fd;
 
        if( !nls )
        {
@@ -53,6 +53,13 @@ static int nl80211_init(void)
                        goto err;
                }
 
+               fd = nl_socket_get_fd(nls->nl_sock);
+               if( fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0 )
+               {
+                       err = -EINVAL;
+                       goto err;
+               }
+
                if( genl_ctrl_alloc_cache(nls->nl_sock, &nls->nl_cache)) {
                        err = -ENOMEM;
                        goto err;
@@ -332,6 +339,9 @@ static char * nl80211_wpasupp_info(const char *ifname, const char *cmd)
        remote_length = sizeof(remote.sun_family) + sprintf(remote.sun_path,
                "/var/run/wpa_supplicant-%s/%s", ifname, ifname);
 
+       if( fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC) < 0 )
+               goto out;
+
        if( connect(sock, (struct sockaddr *) &remote, remote_length) )
                goto out;