aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/fhandler_socket.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-10-10 16:07:46 +0000
committerCorinna Vinschen <corinna@vinschen.de>2007-10-10 16:07:46 +0000
commit4797f5bca35d9598ae6ac4a021ef37ba3f1a75e0 (patch)
tree3fb7aa56e97c09c9a58fd87d6fae863c2f24e79a /winsup/cygwin/fhandler_socket.cc
parent97f0a0ecf68bc21371bd16611e6ae3155dad3642 (diff)
downloadnewlib-4797f5bca35d9598ae6ac4a021ef37ba3f1a75e0.zip
newlib-4797f5bca35d9598ae6ac4a021ef37ba3f1a75e0.tar.gz
newlib-4797f5bca35d9598ae6ac4a021ef37ba3f1a75e0.tar.bz2
* fhandler_socket.cc (fhandler_socket::bind): Open file for deletion,
too. Don't write to file and especially don't close handle if file couldn't be created. Set delete disposition if writing failed, instead of calling unlink_nt.
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r--winsup/cygwin/fhandler_socket.cc41
1 files changed, 24 insertions, 17 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index a901dfd..ba87ebe 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -831,7 +831,7 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
HANDLE fh;
OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io;
- status = NtCreateFile (&fh, GENERIC_WRITE | SYNCHRONIZE,
+ status = NtCreateFile (&fh, DELETE | FILE_GENERIC_WRITE,
pc.get_object_attr (attr, sa), &io, NULL, fattr,
FILE_SHARE_VALID_FLAGS, FILE_CREATE,
FILE_NON_DIRECTORY_FILE
@@ -845,24 +845,31 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
else
__seterrno_from_nt_status (status);
}
-
- char buf[sizeof (SOCKET_COOKIE) + 80];
- __small_sprintf (buf, "%s%u %c ", SOCKET_COOKIE, sin.sin_port, get_socket_type () == SOCK_STREAM ? 's' : get_socket_type () == SOCK_DGRAM ? 'd' : '-');
- af_local_set_secret (strchr (buf, '\0'));
- DWORD blen = strlen (buf) + 1;
- status = NtWriteFile (fh, NULL, NULL, NULL, &io, buf, blen, NULL, 0);
- NtClose (fh);
- if (!NT_SUCCESS (status))
- {
- extern NTSTATUS unlink_nt (path_conv &pc);
-
- __seterrno_from_nt_status (status);
- unlink_nt (pc);
- }
else
{
- set_sun_path (un_addr->sun_path);
- res = 0;
+ char buf[sizeof (SOCKET_COOKIE) + 80];
+ __small_sprintf (buf, "%s%u %c ", SOCKET_COOKIE, sin.sin_port,
+ get_socket_type () == SOCK_STREAM ? 's'
+ : get_socket_type () == SOCK_DGRAM ? 'd' : '-');
+ af_local_set_secret (strchr (buf, '\0'));
+ DWORD blen = strlen (buf) + 1;
+ status = NtWriteFile (fh, NULL, NULL, NULL, &io, buf, blen, NULL, 0);
+ if (!NT_SUCCESS (status))
+ {
+ __seterrno_from_nt_status (status);
+ FILE_DISPOSITION_INFORMATION fdi = { TRUE };
+ status = NtSetInformationFile (fh, &io, &fdi, sizeof fdi,
+ FileDispositionInformation);
+ if (!NT_SUCCESS (status))
+ debug_printf ("Setting delete dispostion failed, status = %p",
+ status);
+ }
+ else
+ {
+ set_sun_path (un_addr->sun_path);
+ res = 0;
+ }
+ NtClose (fh);
}
#undef un_addr
}