This is the mail archive of the
cygwin
mailing list for the Cygwin project.
chmod() converts local domain socket file to regular file
- From: Andrey Simonenko <simon at comsys dot ntu-kpi dot kiev dot ua>
- To: cygwin at cygwin dot com
- Date: Fri, 27 Apr 2007 12:58:46 +0300
- Subject: chmod() converts local domain socket file to regular file
Greetings,
Has Cygwin 1.5.24-2 and XP.
A program creates local domain socket. If S_IRUSR bit is
removed from the socket file, then this file is converted to a
regular file.
This program shows this problem (check the output of "ls -l sock"):
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
int
main(void)
{
struct sockaddr_un addr;
int sd;
sd = socket(PF_LOCAL, SOCK_DGRAM, 0);
if (sd < 0)
return 1;
memset(&addr, 0, sizeof(addr));
addr.sun_family = PF_LOCAL;
strncpy(addr.sun_path, "./sock", sizeof(addr.sun_path) - 1);
if (bind(sd, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0)
return 1;
if (chmod(addr.sun_path, S_IWUSR) < 0)
return 1;
if (listen(sd, 4) < 0)
return 1;
if (close(sd) < 0)
return 1;
return 0;
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/