mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-22 00:38:06 +08:00
* fhandler_socket.cc (fhandler_socket::bind): Open and write socket
file using Win32 calls.
This commit is contained in:
parent
9d913f071f
commit
5a082e9eac
@ -1,3 +1,8 @@
|
|||||||
|
2003-03-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* fhandler_socket.cc (fhandler_socket::bind): Open and write socket
|
||||||
|
file using Win32 calls.
|
||||||
|
|
||||||
2003-03-01 Corinna Vinschen <corinna@vinschen.de>
|
2003-03-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_socket.cc (get_inet_addr): Open and read socket file using
|
* fhandler_socket.cc (get_inet_addr): Open and read socket file using
|
||||||
|
@ -446,7 +446,6 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
|
|||||||
#define un_addr ((struct sockaddr_un *) name)
|
#define un_addr ((struct sockaddr_un *) name)
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int len = sizeof sin;
|
int len = sizeof sin;
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (strlen (un_addr->sun_path) >= UNIX_PATH_LEN)
|
if (strlen (un_addr->sun_path) >= UNIX_PATH_LEN)
|
||||||
{
|
{
|
||||||
@ -472,35 +471,48 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
|
|||||||
sin.sin_port = ntohs (sin.sin_port);
|
sin.sin_port = ntohs (sin.sin_port);
|
||||||
debug_printf ("AF_LOCAL: socket bound to port %u", sin.sin_port);
|
debug_printf ("AF_LOCAL: socket bound to port %u", sin.sin_port);
|
||||||
|
|
||||||
/* bind must fail if file system socket object already exists
|
path_conv pc (un_addr->sun_path, PC_SYM_FOLLOW);
|
||||||
so _open () is called with O_EXCL flag. */
|
if (pc.error)
|
||||||
fd = ::open (un_addr->sun_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0);
|
{
|
||||||
if (fd < 0)
|
set_errno (pc.error);
|
||||||
{
|
|
||||||
if (get_errno () == EEXIST)
|
|
||||||
set_errno (EADDRINUSE);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if (pc.exists ())
|
||||||
|
{
|
||||||
|
set_errno (EADDRINUSE);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
mode_t mode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask;
|
||||||
|
DWORD attr = FILE_ATTRIBUTE_SYSTEM;
|
||||||
|
if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
||||||
|
attr |= FILE_ATTRIBUTE_READONLY;
|
||||||
|
SECURITY_ATTRIBUTES sa = sec_none;
|
||||||
|
if (allow_ntsec && pc.has_acls ())
|
||||||
|
set_security_attribute (mode, &sa, alloca (4096), 4096);
|
||||||
|
HANDLE fh = CreateFile (pc, GENERIC_WRITE, 0, &sa, CREATE_NEW, attr, 0);
|
||||||
|
if (fh == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
if (GetLastError () == ERROR_ALREADY_EXISTS)
|
||||||
|
set_errno (EADDRINUSE);
|
||||||
|
else
|
||||||
|
__seterrno ();
|
||||||
|
}
|
||||||
|
|
||||||
set_connect_secret ();
|
set_connect_secret ();
|
||||||
|
|
||||||
char buf[sizeof (SOCKET_COOKIE) + 80];
|
char buf[sizeof (SOCKET_COOKIE) + 80];
|
||||||
__small_sprintf (buf, "%s%u ", SOCKET_COOKIE, sin.sin_port);
|
__small_sprintf (buf, "%s%u ", SOCKET_COOKIE, sin.sin_port);
|
||||||
get_connect_secret (strchr (buf, '\0'));
|
get_connect_secret (strchr (buf, '\0'));
|
||||||
len = strlen (buf) + 1;
|
DWORD blen = strlen (buf) + 1;
|
||||||
|
if (!WriteFile (fh, buf, blen, &blen, 0))
|
||||||
/* Note that the terminating nul is written. */
|
{
|
||||||
if (::write (fd, buf, len) != len)
|
__seterrno ();
|
||||||
{
|
CloseHandle (fh);
|
||||||
save_errno here;
|
DeleteFile (pc);
|
||||||
::close (fd);
|
|
||||||
unlink (un_addr->sun_path);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::close (fd);
|
CloseHandle (fh);
|
||||||
chmod (un_addr->sun_path,
|
|
||||||
(S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask);
|
|
||||||
set_sun_path (un_addr->sun_path);
|
set_sun_path (un_addr->sun_path);
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user