Mail Archives: cygwin/2002/01/01/19:00:29
> -----Original Message-----
> From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com]On Behalf
> Of Corinna Vinschen
> Sent: Tuesday, January 01, 2002 4:07 PM
> To: cygwin AT cygwin DOT com
> Subject: Re: duplicate regexec/regcomp functions detected
>
>
> On Mon, Dec 31, 2001 at 07:53:28PM +0100, Ralf Habacker wrote:
> > > >- unix domain socket - The above mentioned os supports creating unix
> > > >domain sockets with previous existing files. On cygwin the unix domain
> > > >sockets couldn't be bound on existing files, so it has to be removed
> > > >first.
> > >
> > > Sounds like a bug. Submit a patch.
>
> It's not a bug, it's Linux compliant behaviour. Try the following
> code on Linux and Cygwin:
>
> ================================== SNIP ==============================
> #include <stdio.h>
> #include <errno.h>
> #include <sys/socket.h>
> #include <sys/un.h>
>
> int
> main(int argc, char **argv)
> {
> int sockfd;
> socklen_t len;
> struct sockaddr_un addr1, addr2;
>
> if (argc != 2)
> {
> fprintf (stderr, "Idiot\n");
> return 1;
> }
> sockfd = socket (AF_LOCAL, SOCK_STREAM, 0);
> if (sockfd < 0)
> {
> fprintf (stderr, "socket: %d, %s\n", errno, strerror (errno));
> return 1;
> }
> memset (&addr1, 0, sizeof addr1);
> addr1.sun_family = AF_LOCAL;
> strncpy (addr1.sun_path, argv[1], sizeof addr1.sun_path - 1);
> if (bind (sockfd, (struct sockaddr *) &addr1, SUN_LEN (&addr1)) < 0)
> {
> fprintf (stderr, "bind: %d, %s\n", errno, strerror (errno));
> return 1;
> }
> len = sizeof addr2;
> if (getsockname (sockfd, (struct sockaddr *) &addr2, &len) < 0)
> {
> fprintf (stderr, "getsockname: %d, %s\n", errno, strerror (errno));
> return 1;
> }
> printf ("bound name = %s, returned len = %d\n", addr2.sun_path, len);
> return 0;
> }
> ================================== SNAP ==============================
>
> Linux:
> ------
> $ gcc -o uds uds.c
> $ ./uds /tmp/foo.bar
> bound name = /tmp/foo.bar, returned len = 15
> $ ./uds /tmp/foo.bar
> bind: 98, Address already in use
>
> Cygwin:
> -------
> $ gcc -o uds uds.c
> $ ./uds /tmp/foo.bar
> bound name = <some random string here>, returned len = 16
> $ ./uds /tmp/foo.bar
> bind: 112, Address already in use
>
> That shows that Cygwin's getsockname() doesn't return a correct
> sockname for unix domain sockets but the bind() call behaves
> correct. An application that depends on (actually undocumented)
> behaviour that a unix domain socket can be rebound is doing something
> wrong.
Thanks for this hints. While porting kdelibs I have had to explicity closed and delete the
socket file before I can bound to it (which wasn't used under other ported os) and as I found
the decribed code in the bind() function, the first thoughts was that this may be the
problem. After this correction I will look at the kde code to identify the called functions.
Perhaps the problem is the getsockname().
After looking in the code I have an additional question. Does cygwin and linux differs in the
possibilites of deleting of open files ? This could be a difference, because I have found
that before binding an unlink() is made, but fails.
Ralf
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -