diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2007-10-10 20:07:46 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2007-10-10 20:07:46 +0400 |
commit | 4797f5bca35d9598ae6ac4a021ef37ba3f1a75e0 (patch) | |
tree | 3fb7aa56e97c09c9a58fd87d6fae863c2f24e79a /winsup | |
parent | 97f0a0ecf68bc21371bd16611e6ae3155dad3642 (diff) |
* 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')
-rw-r--r-- | winsup/cygwin/ChangeLog | 7 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 41 |
2 files changed, 31 insertions, 17 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8af5af788..169302d44 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2007-10-10 Corinna Vinschen <corinna@vinschen.de> + + * 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. + 2007-09-27 Corinna Vinschen <corinna@vinschen.de> * ntdll.h (struct _FILE_COMPRESSION_INFORMATION): Align with definition diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index a901dfd10..ba87ebe45 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 } |