* dtable.cc (dtable::init_std_file_from_handle): Attempt stronger detection of
invalid handle. (handle_to_fn): Detect pathological condition where NT resets the buffer pointer to NULL on an invalid handle.
This commit is contained in:
parent
654783b62f
commit
cef6955910
|
@ -1,3 +1,10 @@
|
||||||
|
2002-05-29 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* dtable.cc (dtable::init_std_file_from_handle): Attempt stronger
|
||||||
|
detection of invalid handle.
|
||||||
|
(handle_to_fn): Detect pathological condition where NT resets the
|
||||||
|
buffer pointer to NULL on an invalid handle.
|
||||||
|
|
||||||
2002-05-28 Christopher Faylor <cgf@redhat.com>
|
2002-05-28 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* fhandler_disk_file.cc (fhandler_disk_file::fstat_helper): Properly
|
* fhandler_disk_file.cc (fhandler_disk_file::fstat_helper): Properly
|
||||||
|
|
|
@ -217,7 +217,7 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
|
||||||
void
|
void
|
||||||
dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
|
dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
|
||||||
{
|
{
|
||||||
int bin;
|
int bin = 0;
|
||||||
const char *name;
|
const char *name;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO buf;
|
CONSOLE_SCREEN_BUFFER_INFO buf;
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
|
@ -229,55 +229,61 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
|
||||||
if (!not_open (fd))
|
if (!not_open (fd))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!handle || handle == INVALID_HANDLE_VALUE)
|
SetLastError (0);
|
||||||
{
|
DWORD ft = GetFileType (handle);
|
||||||
fds[fd] = NULL;
|
if (ft == FILE_TYPE_UNKNOWN && GetLastError () == ERROR_INVALID_HANDLE)
|
||||||
return;
|
name = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (__fmode)
|
|
||||||
bin = __fmode;
|
|
||||||
else
|
else
|
||||||
bin = binmode ?: 0;
|
{
|
||||||
|
if (__fmode)
|
||||||
|
bin = __fmode;
|
||||||
|
else
|
||||||
|
bin = binmode ?: 0;
|
||||||
|
|
||||||
/* See if we can consoleify it - if it is a console,
|
/* See if we can consoleify it - if it is a console,
|
||||||
don't open it in binary. That will screw up our crlfs*/
|
don't open it in binary. That will screw up our crlfs*/
|
||||||
if (GetConsoleScreenBufferInfo (handle, &buf))
|
if (GetConsoleScreenBufferInfo (handle, &buf))
|
||||||
{
|
{
|
||||||
if (ISSTATE (myself, PID_USETTY))
|
if (ISSTATE (myself, PID_USETTY))
|
||||||
name = "/dev/tty";
|
name = "/dev/tty";
|
||||||
|
else
|
||||||
|
name = "/dev/conout";
|
||||||
|
bin = 0;
|
||||||
|
}
|
||||||
|
else if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &buf))
|
||||||
|
{
|
||||||
|
if (ISSTATE (myself, PID_USETTY))
|
||||||
|
name = "/dev/tty";
|
||||||
|
else
|
||||||
|
name = "/dev/conin";
|
||||||
|
bin = 0;
|
||||||
|
}
|
||||||
|
else if (ft == FILE_TYPE_PIPE)
|
||||||
|
{
|
||||||
|
if (fd == 0)
|
||||||
|
name = "/dev/piper";
|
||||||
|
else
|
||||||
|
name = "/dev/pipew";
|
||||||
|
if (bin == 0)
|
||||||
|
bin = O_BINARY;
|
||||||
|
}
|
||||||
|
else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0)
|
||||||
|
name = "/dev/socket";
|
||||||
|
else if (GetCommState (handle, &dcb))
|
||||||
|
name = "/dev/ttyS0"; // FIXME - determine correct device
|
||||||
else
|
else
|
||||||
name = "/dev/conout";
|
name = handle_to_fn (handle, (char *) alloca (MAX_PATH + 100));
|
||||||
bin = 0;
|
|
||||||
}
|
}
|
||||||
else if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &buf))
|
|
||||||
{
|
if (!name)
|
||||||
if (ISSTATE (myself, PID_USETTY))
|
fds[fd] = NULL;
|
||||||
name = "/dev/tty";
|
|
||||||
else
|
|
||||||
name = "/dev/conin";
|
|
||||||
bin = 0;
|
|
||||||
}
|
|
||||||
else if (GetFileType (handle) == FILE_TYPE_PIPE)
|
|
||||||
{
|
|
||||||
if (fd == 0)
|
|
||||||
name = "/dev/piper";
|
|
||||||
else
|
|
||||||
name = "/dev/pipew";
|
|
||||||
if (bin == 0)
|
|
||||||
bin = O_BINARY;
|
|
||||||
}
|
|
||||||
else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0)
|
|
||||||
name = "/dev/socket";
|
|
||||||
else if (GetCommState (handle, &dcb))
|
|
||||||
name = "/dev/ttyS0"; // FIXME - determine correct device
|
|
||||||
else
|
else
|
||||||
name = handle_to_fn (handle, (char *) alloca (MAX_PATH + 100));
|
{
|
||||||
|
path_conv pc;
|
||||||
path_conv pc;
|
build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, bin);
|
||||||
build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, bin);
|
set_std_handle (fd);
|
||||||
set_std_handle (fd);
|
paranoid_printf ("fd %d, handle %p", fd, handle);
|
||||||
paranoid_printf ("fd %d, handle %p", fd, handle);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandler_base *
|
fhandler_base *
|
||||||
|
@ -736,6 +742,11 @@ handle_to_fn (HANDLE h, char *posix_fn)
|
||||||
ntfn->Name.Buffer = (WCHAR *) ntfn + 1;
|
ntfn->Name.Buffer = (WCHAR *) ntfn + 1;
|
||||||
|
|
||||||
DWORD res = NtQueryObject (h, ObjectNameInformation, ntfn, sizeof (fnbuf), NULL);
|
DWORD res = NtQueryObject (h, ObjectNameInformation, ntfn, sizeof (fnbuf), NULL);
|
||||||
|
|
||||||
|
// NT seems to do this on an unopened file
|
||||||
|
if (!ntfn->Name.Buffer)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
strcpy (posix_fn, "some disk file");
|
strcpy (posix_fn, "some disk file");
|
||||||
|
|
Loading…
Reference in New Issue