The attached test case creates a socket file /tmp/mysocket and tries to rename
it to /tmp/newsocket. But the new name is actually /tmp/newsocket.lnk:
$ gcc -o rename_socket rename_socket.c
$ ./rename_socket.exe
$ ls -F /tmp/newsocket*
/tmp/newsocket.lnk=
I think I have a simple fix, which I'll send to cygwin-patches shortly.
Ken
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/un.h>
#include <sys/socket.h>
int
main ()
{
const char *old = "/tmp/mysocket";
const char *new = "/tmp/newsocket";
const char *bad = "/tmp/newsocket.lnk";
struct sockaddr_un addr;
int fd;
if (unlink (old) == -1 && errno != ENOENT)
{
perror ("unlink");
exit (1);
}
if (unlink (new) == -1 && errno != ENOENT)
{
perror ("unlink");
exit (1);
}
if (unlink (bad) == -1 && errno != ENOENT)
{
perror ("unlink");
exit (1);
}
memset (&addr, 0, sizeof (struct sockaddr_un));
addr.sun_family = AF_UNIX;
strncpy (addr.sun_path, old, sizeof (addr.sun_path) - 1);
fd = socket (AF_UNIX, SOCK_STREAM, 0);
if (fd == -1)
{
perror ("socket");
exit (1);
}
if (bind (fd, (struct sockaddr *) &addr, sizeof (struct sockaddr_un)) == -1)
{
perror ("bind");
exit (1);
}
if (rename (old, new) == -1)
{
perror ("rename");
exit (1);
}
exit (0);
}
--
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