RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-08-30 Thread Andrew Luo
t (JNIEnv *env, jclass cl) { int sp[2]; -if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { +if (NET_SocketPair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); return; } @@ -180,7 +180,7 @@

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-30 Thread Andrew Luo
jclass cl) { int sp[2]; -if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { +if (NET_SocketPair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); return; } @@ -180,7 +180,7 @@ return 0; } -

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-26 Thread Andrew Luo
On Behalf Of Ivan Gerasimov Sent: Wednesday, July 25, 2018 10:04 PM To: Chris Hegarty Cc: net-dev@openjdk.java.net Subject: Re: [PATCH] SOCK_CLOEXEC for opening sockets Hi Chris! A couple of minor comments. 1) if (s != -1 || (s == -1 && errno != EINVAL)) { This can be simplified t

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-25 Thread Ivan Gerasimov
Hi Chris! A couple of minor comments. 1) if (s != -1 || (s == -1 && errno != EINVAL)) { This can be simplified to if (s != -1 || errno != EINVAL) { 2) What about sockets created with accept(): Shouldn't NET_Accept be modified to set O_CLOEXEC as well? On Linux accept4() can be used to

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-25 Thread Alan Bateman
On 25/07/2018 13:49, Chris Hegarty wrote: : The updates to the various site to use the NET_* functions are fine. However, I think the new functions in net_util_md.c could be cleaner. I think it would be better to fallback to socket/socketpair + fcntl when the initial call fails with EINVAL.

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-25 Thread Chris Hegarty
Alan, > On 25 Jul 2018, at 08:24, Alan Bateman wrote: > > ... > > As I said previously, the patch isn't complete so native code calling > fork/exec may still have to deal with other file descriptors that are > inherited into the child. I don't object to doing this in phases of course > but

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-25 Thread Alan Bateman
On 24/07/2018 21:34, Chris Hegarty wrote: On 19 Jul 2018, at 18:41, Andrew Luo wrote: Just checking - is there any other changes that I should make to the patch, or anything else you guys need me to do? A webrev genderated from Andrew’s patch along with: 1) some additional includes of

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-24 Thread Chris Hegarty
> On 19 Jul 2018, at 18:41, Andrew Luo > wrote: > > Just checking - is there any other changes that I should make to the patch, > or anything else you guys need me to do? A webrev genderated from Andrew’s patch along with: 1) some additional includes of “net_util_md.h” in several missing

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-19 Thread Andrew Luo
: [PATCH] SOCK_CLOEXEC for opening sockets Thanks for the feedback. Made those changes (reverted src/java.base/linux/native/libnio/fs/LinuxWatchService.c): diff --git a/make/lib/Lib-jdk.net.gmk b/make/lib/Lib-jdk.net.gmk --- a/make/lib/Lib-jdk.net.gmk +++ b/make/lib/Lib-jdk.net.gmk @@ -35,7

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-17 Thread Andrew Luo
} @@ -180,7 +180,7 @@ return 0; } -fd = socket(domain, (oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP); +fd = NET_Socket(domain, (oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP); if (fd < 0) { return handleSocketError(env, errno); Thanks

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-17 Thread Alan Bateman
On 17/07/2018 07:33, Andrew Luo wrote: Great, thanks. By the way, I do see other places where we use NET_* functions in libnio, but if you prefer that I duplicate that code instead, It's okay for the code in libnio/ch to use the NET_* functions. The issue is the changes to libnio/fs which is

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-17 Thread Andrew Luo
OCK_SEQPACKET), IPPROTO_SCTP); if (fd < 0) { return handleSocketError(env, errno); By the way, I only have x86 systems (and VMs) - any way I can test this on AIX, or what is the preferred way to ensure my changes will build properly on all platforms? Thanks, -Andrew -Origin

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-16 Thread Chris Hegarty
, 2018 11:59 PM *To:* Andrew Luo *Cc:* Martin Buchholz ; net-dev@openjdk.java.net *Subject:* Re: [PATCH] SOCK_CLOEXEC for opening sockets On 12/07/2018 05:55, Andrew Luo wrote: Ok, fixed a few more places (and a bug where fcntl was being run on a -1 fd).  Patch is below, let me know

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-16 Thread Alan Bateman
On 12/07/2018 08:21, Andrew Luo wrote: Thanks, I can refactor it.  I’m not as familiar with the OpenJDK architecture – should I just duplicate the function into libnio or is there some common utility library that I should move it into?  Also, let me know what in net_util_* needs cleanup. 

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-12 Thread Andrew Luo
). Thanks, -Andrew From: Alan Bateman Sent: Wednesday, July 11, 2018 11:59 PM To: Andrew Luo Cc: Martin Buchholz ; net-dev@openjdk.java.net Subject: Re: [PATCH] SOCK_CLOEXEC for opening sockets On 12/07/2018 05:55, Andrew Luo wrote: Ok, fixed a few more places (and a bug where fcntl was being

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-12 Thread Alan Bateman
On 12/07/2018 05:55, Andrew Luo wrote: Ok, fixed a few more places (and a bug where fcntl was being run on a -1 fd).  Patch is below, let me know if there’s any other suggestions/etc. The file system code should not be calling into NET_* functions. The changes to net_util_* will also need

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-11 Thread Andrew Luo
ocket(domain, type, 0); +fd = NET_Socket(domain, type, 0); if (fd < 0) { return handleSocketError(env, errno); } From: Alan Bateman Sent: Wednesday, July 11, 2018 12:12 AM To: Andrew Luo ; Norman Maurer Cc: Martin Buchholz ; net-dev@openjdk.java.net Subject: Re: [PATCH

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-11 Thread Alan Bateman
int oldfd, int newfd); int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout); *From:*Norman Maurer *Sent:* Tuesday, July 10, 2018 9:55 AM *To:* Alan Bateman *Cc:* Martin Buchholz ; Andrew Luo ; net-dev@openjdk.java.net *Subject:* Re: [PATCH] SOCK_CLOEXEC for opening sockets +

RE: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-11 Thread Andrew Luo
oll(struct pollfd *ufds, unsigned int nfds, int timeout); From: Norman Maurer Sent: Tuesday, July 10, 2018 9:55 AM To: Alan Bateman Cc: Martin Buchholz ; Andrew Luo ; net-dev@openjdk.java.net Subject: Re: [PATCH] SOCK_CLOEXEC for opening sockets +1 I think this makes a lot of sense On 10. J

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-10 Thread Norman Maurer
+1 I think this makes a lot of sense > On 10. Jul 2018, at 17:54, Alan Bateman wrote: > > On 10/07/2018 17:40, Martin Buchholz wrote: >> I agree with this approach - it parallels the efforts made with O_CLOEXEC in >> past years. >> >> According to >>

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-10 Thread Alan Bateman
On 10/07/2018 17:40, Martin Buchholz wrote: I agree with this approach - it parallels the efforts made with O_CLOEXEC in past years. According to https://www.freebsd.org/cgi/man.cgi?query=socket=2 SOCK_CLOEXEC is also available on freebsd. This is something that doesn't come up too often, I

Re: [PATCH] SOCK_CLOEXEC for opening sockets

2018-07-10 Thread Martin Buchholz
I agree with this approach - it parallels the efforts made with O_CLOEXEC in past years. According to https://www.freebsd.org/cgi/man.cgi?query=socket=2 SOCK_CLOEXEC is also available on freebsd. On Tue, Jul 10, 2018 at 1:36 AM, Andrew Luo < andrewluotechnolog...@outlook.com> wrote: > Hi, > > >

[PATCH] SOCK_CLOEXEC for opening sockets

2018-07-10 Thread Andrew Luo
Hi, I want to propose to use SOCK_CLOEXEC when opening sockets in the OpenJDK. I ran into some issues when forking processes (in JNI/C/C++/native code) on Linux where OpenJDK had opened a socket (in Java code). The child process ends up inheriting a file descriptor to the same socket, which