]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: set the close-on-exec flag for descriptors
authorAndrey Vagin <avagin@openvz.org>
Tue, 4 Jun 2013 08:01:14 +0000 (12:01 +0400)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 4 Jun 2013 16:11:06 +0000 (09:11 -0700)
Otherwise a program executed by "ip netns exec" has two extra
descriptors.

$ ip netns exec test /bin/bash
$ lsof -p $$
...
bash    817 root    0u   CHR  136,0       0t0          3 /dev/pts/0
bash    817 root    1u   CHR  136,0       0t0          3 /dev/pts/0
bash    817 root    2u   CHR  136,0       0t0          3 /dev/pts/0
bash    817 root    3u  sock    0,6       0t0      13386 protocol: NETLINK
bash    817 root    4r   REG    0,3         0 4026532155 net
bash    817 root  255u   CHR  136,0       0t0          3 /dev/pts/0

Cc: Stephen Hemminger <stephen@networkplumber.org>
Reported-by: Dilip Daya <dilip.daya@hp.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
ip/ipnetns.c
lib/libnetlink.c

index c9bc20aeea52255c47aac93043e20983f64fde58..fa2b6810b0ba8b71c5b7a7a49e4c13804a352c29 100644 (file)
@@ -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));
index b17e1aae9b69e3e497263a41f629b2debe90dd99..9e2a7958e9dd4ec558c224cab33dd79db7b7dc77 100644 (file)
@@ -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;