From: "Maciej Żenczykowski" <zenczykowski@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] mark newly opened fds as FD_CLOEXEC (close on exec) [part 2]
Date: Wed, 21 Mar 2012 13:40:16 -0700 [thread overview]
Message-ID: <CANP3RGdUHYzLKaGR2APoWzbV2LSquujXoNdsTN-yYs8=bT=5kw@mail.gmail.com> (raw)
In-Reply-To: <1332361663.9433.8.camel@edumazet-glaptop>
But that's a kernel feature, and I don't think we can rely on it being
present in iptables userspace (it has to be backwards compatible to
IMHO at least back to 2.6.9 if at all possible),
and adding the "try with flag, if fails, retry without flag and
manually set it" logic seems overkill.
I think such details only matter for multithreaded programs with exec races.
Which I don't believe to be the case here.
On Wed, Mar 21, 2012 at 1:27 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Wed, 2012-03-21 at 03:52 -0700, Maciej Żenczykowski wrote:
>> From: Maciej Żenczykowski <maze@google.com>
>>
>> This is iptables-1.4.11-cloexec.patch from Fedora 18 iptables source
>> rpm, in particular:
>> http://kojipkgs.fedoraproject.org/packages/iptables/1.4.12.2/4.fc18/src/iptables-1.4.12.2-4.fc18.src.rpm
>>
>> Signed-off-by: Maciej Żenczykowski <maze@google.com>
>> ---
>> extensions/libxt_set.h | 7 +++++++
>> libiptc/libiptc.c | 8 ++++++++
>> 2 files changed, 15 insertions(+), 0 deletions(-)
>>
>> diff --git a/extensions/libxt_set.h b/extensions/libxt_set.h
>> index 4ac84fa9c022..47c3f5b6f5d4 100644
>> --- a/extensions/libxt_set.h
>> +++ b/extensions/libxt_set.h
>> @@ -2,6 +2,7 @@
>> #define _LIBXT_SET_H
>>
>> #include <unistd.h>
>> +#include <fcntl.h>
>> #include <sys/types.h>
>> #include <sys/socket.h>
>> #include <errno.h>
>> @@ -23,6 +24,12 @@ get_version(unsigned *version)
>> xtables_error(OTHER_PROBLEM,
>> "Can't open socket to ipset.\n");
>>
>> + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) == -1) {
>> + xtables_error(OTHER_PROBLEM,
>> + "Could not set close on exec: %s\n",
>> + strerror(errno));
>> + }
>> +
>> req_version.op = IP_SET_OP_VERSION;
>> res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req_version, &size);
>> if (res != 0)
>> diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
>> index 13e41d525f28..63965e738596 100644
>> --- a/libiptc/libiptc.c
>> +++ b/libiptc/libiptc.c
>> @@ -29,6 +29,8 @@
>> * - performance work: speedup initial ruleset parsing.
>> * - sponsored by ComX Networks A/S (http://www.comx.dk/)
>> */
>> +#include <unistd.h>
>> +#include <fcntl.h>
>> #include <sys/types.h>
>> #include <sys/socket.h>
>> #include <stdbool.h>
>> @@ -1316,6 +1318,12 @@ TC_INIT(const char *tablename)
>> if (sockfd < 0)
>> return NULL;
>>
>> + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) == -1) {
>> + fprintf(stderr, "Could not set close on exec: %s\n",
>> + strerror(errno));
>> + abort();
>> + }
>> +
>> retry:
>> s = sizeof(info);
>>
>
> Looks fine, but since commit a677a039b (flag parameters: socket and
> socketpair) from Ulrich Drepper, we can pass SOCK_CLOEXEC directly in
> the socket() call, thus avoiding extra fcntl() call.
>
> Not relevant to iptables (opening this socket in iptables is not
> performance critical), but worth to mention for reference.
>
>
>
--
Maciej A. Żenczykowski
Kernel Networking Developer @ Google
1600 Amphitheatre Parkway, Mountain View, CA 94043
tel: +1 (650) 253-0062
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-03-21 20:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-21 10:52 [PATCH] mark newly opened fds as FD_CLOEXEC (close on exec) [part 2] Maciej Żenczykowski
2012-03-21 20:27 ` Eric Dumazet
2012-03-21 20:40 ` Maciej Żenczykowski [this message]
2012-03-21 20:44 ` Eric Dumazet
2012-03-21 20:50 ` Maciej Żenczykowski
2012-03-22 11:21 ` Pablo Neira Ayuso
2012-03-23 10:26 ` Pablo Neira Ayuso
2012-03-24 9:11 ` Maciej Żenczykowski
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='CANP3RGdUHYzLKaGR2APoWzbV2LSquujXoNdsTN-yYs8=bT=5kw@mail.gmail.com' \
--to=zenczykowski@gmail.com \
--cc=eric.dumazet@gmail.com \
--cc=netfilter-devel@vger.kernel.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).