From: Andrey Vagin <avagin@openvz.org>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, Andrey Vagin <avagin@openvz.org>
Subject: [PATCH] ip: set the close-on-exec flag for descriptors
Date: Tue, 4 Jun 2013 12:01:14 +0400 [thread overview]
Message-ID: <1370332874-584-1-git-send-email-avagin@openvz.org> (raw)
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 | 2 +-
lib/libnetlink.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index c9bc20a..fa2b681 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 b17e1aa..9e2a795 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;
--
1.8.2
next reply other threads:[~2013-06-04 8:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 8:01 Andrey Vagin [this message]
2013-06-04 16:11 ` [PATCH] ip: set the close-on-exec flag for descriptors Stephen Hemminger
2013-07-08 14:17 ` Eric Dumazet
2013-07-08 15:51 ` Andrey Wagin
2013-07-08 16:05 ` Eric Dumazet
2013-07-08 19:23 ` Andrey Wagin
2013-07-08 19:50 ` Stephen Hemminger
2013-07-08 19:57 ` Stephen Hemminger
2013-07-08 20:00 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370332874-584-1-git-send-email-avagin@openvz.org \
--to=avagin@openvz.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).