Cygwin: AF_UNIX: open_pipe: fix invalid handle error
Commit debdfb8b
, "Cygwin: AF_UNIX: Rework internal methods to return
HANDLEs", removed a set_handle call. As a result, the attempt to
exchange socket info fails with "Invalid Handle".
Fix this by moving the send_sock_info call into a new 'xchg_sock_info'
method, which is then invoked by the callers of open_pipe if
necessary, after they have called set_handle.
Also, call recv_peer_info in addition to send_sock_info when
exchanging socket information.
Remove the last argument of open_pipe, which is no longer needed.
Adjust all callers.
This commit is contained in:
parent
0f800bf44a
commit
add34a7b53
|
@ -1019,8 +1019,8 @@ class fhandler_socket_unix : public fhandler_socket
|
|||
static NTSTATUS npfs_handle (HANDLE &nph);
|
||||
HANDLE create_pipe (bool single_instance);
|
||||
HANDLE create_pipe_instance ();
|
||||
NTSTATUS open_pipe (HANDLE &ph, PUNICODE_STRING pipe_name,
|
||||
bool xchg_sock_info);
|
||||
NTSTATUS open_pipe (HANDLE &ph, PUNICODE_STRING pipe_name);
|
||||
void xchg_sock_info ();
|
||||
int wait_pipe (PUNICODE_STRING pipe_name);
|
||||
int connect_pipe (PUNICODE_STRING pipe_name);
|
||||
int listen_pipe ();
|
||||
|
|
|
@ -956,8 +956,7 @@ fhandler_socket_unix::create_pipe_instance ()
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
fhandler_socket_unix::open_pipe (HANDLE &pipe, PUNICODE_STRING pipe_name,
|
||||
bool xchg_sock_info)
|
||||
fhandler_socket_unix::open_pipe (HANDLE &pipe, PUNICODE_STRING pipe_name)
|
||||
{
|
||||
NTSTATUS status;
|
||||
HANDLE npfsh;
|
||||
|
@ -975,14 +974,18 @@ fhandler_socket_unix::open_pipe (HANDLE &pipe, PUNICODE_STRING pipe_name,
|
|||
sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
status = NtOpenFile (&ph, access, &attr, &io, sharing, 0);
|
||||
if (NT_SUCCESS (status))
|
||||
{
|
||||
pipe = ph;
|
||||
if (xchg_sock_info)
|
||||
send_sock_info (false);
|
||||
}
|
||||
pipe = ph;
|
||||
return status;
|
||||
}
|
||||
|
||||
/* FIXME: check for errors? */
|
||||
void
|
||||
fhandler_socket_unix::xchg_sock_info ()
|
||||
{
|
||||
send_sock_info (false);
|
||||
recv_peer_info ();
|
||||
}
|
||||
|
||||
struct conn_wait_info_t
|
||||
{
|
||||
fhandler_socket_unix *fh;
|
||||
|
@ -1082,7 +1085,7 @@ fhandler_socket_unix::connect_pipe (PUNICODE_STRING pipe_name)
|
|||
|
||||
/* Try connecting first. If it doesn't work, wait for the pipe
|
||||
to become available. */
|
||||
status = open_pipe (ph, pipe_name, get_socket_type () != SOCK_DGRAM);
|
||||
status = open_pipe (ph, pipe_name);
|
||||
if (STATUS_PIPE_NO_INSTANCE_AVAILABLE (status))
|
||||
return wait_pipe (pipe_name);
|
||||
if (!NT_SUCCESS (status))
|
||||
|
@ -1092,6 +1095,8 @@ fhandler_socket_unix::connect_pipe (PUNICODE_STRING pipe_name)
|
|||
return -1;
|
||||
}
|
||||
set_handle (ph);
|
||||
if (get_socket_type () != SOCK_DGRAM)
|
||||
xchg_sock_info ();
|
||||
so_error (0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1333,8 +1338,7 @@ fhandler_socket_unix::wait_pipe_thread (PUNICODE_STRING pipe_name)
|
|||
{
|
||||
HANDLE ph;
|
||||
|
||||
status = open_pipe (ph, pipe_name,
|
||||
get_socket_type () != SOCK_DGRAM);
|
||||
status = open_pipe (ph, pipe_name);
|
||||
if (STATUS_PIPE_NO_INSTANCE_AVAILABLE (status))
|
||||
{
|
||||
/* Another concurrent connect grabbed the pipe instance
|
||||
|
@ -1351,7 +1355,11 @@ fhandler_socket_unix::wait_pipe_thread (PUNICODE_STRING pipe_name)
|
|||
else if (!NT_SUCCESS (status))
|
||||
error = geterrno_from_nt_status (status);
|
||||
else
|
||||
set_handle (ph);
|
||||
{
|
||||
set_handle (ph);
|
||||
if (get_socket_type () != SOCK_DGRAM)
|
||||
xchg_sock_info ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATUS_OBJECT_NAME_NOT_FOUND:
|
||||
|
@ -1463,7 +1471,7 @@ fhandler_socket_unix::socketpair (int af, int type, int protocol, int flags,
|
|||
connect_state (listener);
|
||||
/* connect 2nd socket, even for DGRAM. There's no difference as far
|
||||
as socketpairs are concerned. */
|
||||
if (fh->open_pipe (ph2, pc.get_nt_native_path (), false) < 0)
|
||||
if (fh->open_pipe (ph2, pc.get_nt_native_path ()) < 0)
|
||||
goto fh_open_pipe_failed;
|
||||
fh->set_handle (ph2);
|
||||
fh->connect_state (connected);
|
||||
|
@ -2020,7 +2028,7 @@ fhandler_socket_unix::sendmsg (const struct msghdr *msg, int flags)
|
|||
set_errno (EPROTOTYPE);
|
||||
__leave;
|
||||
}
|
||||
status = open_pipe (ph, &pipe_name, false);
|
||||
status = open_pipe (ph, &pipe_name);
|
||||
if (!NT_SUCCESS (status))
|
||||
{
|
||||
__seterrno_from_nt_status (status);
|
||||
|
|
Loading…
Reference in New Issue