public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Renaming a socket file adds ".lnk" to the name
@ 2019-07-18 19:35 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-07-18 19:35 UTC (permalink / raw)
  To: cygwin

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

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

[-- Attachment #2: rename_socket.c --]
[-- Type: text/plain, Size: 1069 bytes --]

#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);
}

[-- 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] only message in thread

only message in thread, other threads:[~2019-07-18 19:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18 19:35 Renaming a socket file adds ".lnk" to the name Ken Brown

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).