diff --git a/ip/ipnetns.c b/ip/ipnetns.c index c9bc20ae..fa2b6810 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -150,7 +150,7 @@ static int netns_exec(int argc, char **argv) name = argv[0]; cmd = argv[1]; snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name); - netns = open(net_path, O_RDONLY); + netns = open(net_path, O_RDONLY | O_CLOEXEC); if (netns < 0) { fprintf(stderr, "Cannot open network namespace \"%s\": %s\n", name, strerror(errno)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index b17e1aae..9e2a7958 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -43,7 +43,7 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, memset(rth, 0, sizeof(*rth)); - rth->fd = socket(AF_NETLINK, SOCK_RAW, protocol); + rth->fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol); if (rth->fd < 0) { perror("Cannot open netlink socket"); return -1;