public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
@ 2018-07-03 10:44 Takashi Yano
  2018-07-03 13:06 ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Yano @ 2018-07-03 10:44 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 964 bytes --]

Named AF_UNIX socket does not work in cygwin1.dll of git HEAD.

A simple test case is attched.

Expected result:
10: 1234567890

Result in cygwin1.dll of git HEAD:
bind: Bad address
unlink: Device or resource busy


It seems that this occures regarding the following commit.

commit 859d215b7e006e5fc60f686ec976e997e35d169b
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Feb 21 21:40:01 2018 +0100

    Cygwin: split out fhandler_socket into inet and local classes

    First cut, still incomplete

    * fhandler_socket is now base class for other socket classes
    * fhandler_socket_inet handles AF_INET and AF_INET6 sockets
    * fhandler_socket_local handles AF_LOCAL/AF_UNIX sockets
    * finally get rid of fdsock by using set_socket_handle in accept4
    * align file-related calls (fstat,  fstatvfs, fchown, fchmod, facl)
      to Linux.

    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>


-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

[-- Attachment #2: sockunix.c --]
[-- Type: text/x-csrc, Size: 1418 bytes --]

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>

#define SOCKNAME "sock_unix"

int main()
{
	int fd;
	struct sockaddr_un sunx;
	pid_t pid;
	ssize_t len;
	char buf[BUFSIZ];
	
	memset(&sunx, 0, sizeof(sunx));
	sunx.sun_family = AF_UNIX;
	strncpy (sunx.sun_path, SOCKNAME, sizeof(sunx.sun_path) -1 );

	pid = fork();
	if (pid) {
		int fd1;
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		if (fd < 0) {
			perror("socket");
			goto end_server;
		}
		if (bind(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("bind");
			goto end_server;
		}
		if (listen(fd, 1) < 0) {
			perror("listen");
			goto end_server;
		}
		fd1 = accept(fd, 0, 0);
		if (fd1 < 0) {
			perror("accept");
			goto end_server;
		}
		while ((len = read(fd1, buf, sizeof(buf))) > 0) {
			buf[len] = '\0';
			printf("%d: %s\n", len, buf);
		}
		close(fd1);
end_server:
		close(fd);
		kill(pid, SIGTERM);
		wait(NULL);
		if (unlink(SOCKNAME) < 0) {
			perror("unlink");
		}
	} else {
		usleep(100000);
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		if (fd < 0) {
			perror("socket");
			goto end_client;
		}
		if (connect(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("connect");
			goto end_client;
		}
		write(fd, "1234567890", 10);
end_client:
		close(fd);
	}
	
	return 0;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-03 10:44 Named AF_UNIX socket not working in cygwin1.dll of git HEAD Takashi Yano
@ 2018-07-03 13:06 ` Corinna Vinschen
  2018-07-03 17:01   ` Takashi Yano
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2018-07-03 13:06 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]

On Jul  3 19:44, Takashi Yano wrote:
> Named AF_UNIX socket does not work in cygwin1.dll of git HEAD.
> 
> A simple test case is attched.
> 
> Expected result:
> 10: 1234567890
> 
> Result in cygwin1.dll of git HEAD:
> bind: Bad address
> unlink: Device or resource busy

I just built git HEAD from scratch four times, with and without
optimization, with and without the preliminary new AF_UNIX code (which
should be unused running your testcase anyway).  WIth each version
your testcase prints

  10: 1234567890

Can you please check what happens in your case and why?


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-03 13:06 ` Corinna Vinschen
@ 2018-07-03 17:01   ` Takashi Yano
  2018-07-03 19:17     ` Takashi Yano
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Yano @ 2018-07-03 17:01 UTC (permalink / raw)
  To: cygwin

Hi Corinna,

On Tue, 3 Jul 2018 15:05:58 +0200
Corinna Vinschen wrote:
> I just built git HEAD from scratch four times, with and without
> optimization, with and without the preliminary new AF_UNIX code (which
> should be unused running your testcase anyway).  WIth each version
> your testcase prints
> 
>   10: 1234567890
> 
> Can you please check what happens in your case and why?

I have check and found this happens only in 32 bit version. I mean
32 bit cygwin on 64 bit windows 10. 64 bit version work as expected.

So far, I am not sure what happens and why.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-03 17:01   ` Takashi Yano
@ 2018-07-03 19:17     ` Takashi Yano
  2018-07-04 10:51       ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Yano @ 2018-07-03 19:17 UTC (permalink / raw)
  To: cygwin

Hi Corinna,

On Wed, 4 Jul 2018 02:01:08 +0900
Takashi Yano wrote:
> I have check and found this happens only in 32 bit version. I mean
> 32 bit cygwin on 64 bit windows 10. 64 bit version work as expected.

I have looked into this problem, and found calling af_local_set_secret()
in fhandler_socket_local::bind() causes exception 0xc0000005.

Calling RtlGenRandom() in af_local_set_secret() may not be as expected.

While building cygwin1.dll in 32 bit environment, following warning is
shown. This is probably the cause.

Warning: resolving _SystemFunction036 by linking to _SystemFunction036@8

I am not sure why, but the following patch seems to be able solve this
problem.

diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index 2e01f30a2..68786f3a4 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -21,7 +21,7 @@
 #undef u_long
 #define u_long __ms_u_long
 #endif
-#include <w32api/ntsecapi.h>
+#include <ntsecapi.h>
 #include <w32api/ws2tcpip.h>
 #include <w32api/mswsock.h>
 #include <unistd.h>

Thank you.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-03 19:17     ` Takashi Yano
@ 2018-07-04 10:51       ` Corinna Vinschen
  2018-07-04 11:49         ` Takashi Yano
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2018-07-04 10:51 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1536 bytes --]

On Jul  4 04:17, Takashi Yano wrote:
> Hi Corinna,
> 
> On Wed, 4 Jul 2018 02:01:08 +0900
> Takashi Yano wrote:
> > I have check and found this happens only in 32 bit version. I mean
> > 32 bit cygwin on 64 bit windows 10. 64 bit version work as expected.
> 
> I have looked into this problem, and found calling af_local_set_secret()
> in fhandler_socket_local::bind() causes exception 0xc0000005.
> 
> Calling RtlGenRandom() in af_local_set_secret() may not be as expected.
> 
> While building cygwin1.dll in 32 bit environment, following warning is
> shown. This is probably the cause.
> 
> Warning: resolving _SystemFunction036 by linking to _SystemFunction036@8
> 
> I am not sure why, but the following patch seems to be able solve this
> problem.
> 
> diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
> index 2e01f30a2..68786f3a4 100644
> --- a/winsup/cygwin/fhandler_socket_local.cc
> +++ b/winsup/cygwin/fhandler_socket_local.cc
> @@ -21,7 +21,7 @@
>  #undef u_long
>  #define u_long __ms_u_long
>  #endif
> -#include <w32api/ntsecapi.h>
> +#include <ntsecapi.h>
>  #include <w32api/ws2tcpip.h>
>  #include <w32api/mswsock.h>
>  #include <unistd.h>
> 
> Thank you.

Thanks for catching.  I pushed your patch (using "" rather than <>
just for clearness) with a description.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-04 10:51       ` Corinna Vinschen
@ 2018-07-04 11:49         ` Takashi Yano
  2018-07-04 12:22           ` Corinna Vinschen
  2018-07-04 12:25           ` Takashi Yano
  0 siblings, 2 replies; 8+ messages in thread
From: Takashi Yano @ 2018-07-04 11:49 UTC (permalink / raw)
  To: cygwin

On Wed, 4 Jul 2018 12:51:08 +0200
Corinna Vinschen wrote:
> Thanks for catching.  I pushed your patch (using "" rather than <>
> just for clearness) with a description.

I have pulled the git HEAD just now, but nothing about this.
Instead, the following patch has been applied.
https://cygwin.com/ml/cygwin-patches/2018-q3/msg00000.html

Isn't that the mis-operation?

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-04 11:49         ` Takashi Yano
@ 2018-07-04 12:22           ` Corinna Vinschen
  2018-07-04 12:25           ` Takashi Yano
  1 sibling, 0 replies; 8+ messages in thread
From: Corinna Vinschen @ 2018-07-04 12:22 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

On Jul  4 20:49, Takashi Yano wrote:
> On Wed, 4 Jul 2018 12:51:08 +0200
> Corinna Vinschen wrote:
> > Thanks for catching.  I pushed your patch (using "" rather than <>
> > just for clearness) with a description.
> 
> I have pulled the git HEAD just now, but nothing about this.
> Instead, the following patch has been applied.
> https://cygwin.com/ml/cygwin-patches/2018-q3/msg00000.html
> 
> Isn't that the mis-operation?

Yes, I rebased patches and confused myself when pushing them.
I pushed your perror patches, too, and all should be well now.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Named AF_UNIX socket not working in cygwin1.dll of git HEAD.
  2018-07-04 11:49         ` Takashi Yano
  2018-07-04 12:22           ` Corinna Vinschen
@ 2018-07-04 12:25           ` Takashi Yano
  1 sibling, 0 replies; 8+ messages in thread
From: Takashi Yano @ 2018-07-04 12:25 UTC (permalink / raw)
  To: cygwin

On Wed, 4 Jul 2018 20:49:12 +0900
Takashi Yano wrote:
> Isn't that the mis-operation?

I confirmed that this patch has been applied.
Sorry for impatience.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-07-04 12:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 10:44 Named AF_UNIX socket not working in cygwin1.dll of git HEAD Takashi Yano
2018-07-03 13:06 ` Corinna Vinschen
2018-07-03 17:01   ` Takashi Yano
2018-07-03 19:17     ` Takashi Yano
2018-07-04 10:51       ` Corinna Vinschen
2018-07-04 11:49         ` Takashi Yano
2018-07-04 12:22           ` Corinna Vinschen
2018-07-04 12:25           ` Takashi Yano

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 read-only IMAP folder(s) and NNTP newsgroup(s).