OSDN Git Service

* dtable.cc (dtable::init_std_file_from_handle): Set dev to
authorcorinna <corinna>
Mon, 19 Apr 2010 16:25:09 +0000 (16:25 +0000)
committercorinna <corinna>
Mon, 19 Apr 2010 16:25:09 +0000 (16:25 +0000)
valid content for ptys.  Remove setting FILE_CREATE_PIPE_INSTANCE
in access flags since it's not needed.  Set the access mask for
kernel objects according to what's returned by NtQueryInformationFile,
info class FileAccessInformation.

winsup/cygwin/ChangeLog
winsup/cygwin/dtable.cc

index 28bce1e..68334b3 100644 (file)
@@ -1,5 +1,13 @@
 2010-04-19  Corinna Vinschen  <corinna@vinschen.de>
 
+       * dtable.cc (dtable::init_std_file_from_handle): Set dev to
+       valid content for ptys.  Remove setting FILE_CREATE_PIPE_INSTANCE
+       in access flags since it's not needed.  Set the access mask for
+       kernel objects according to what's returned by NtQueryInformationFile,
+       info class FileAccessInformation.
+
+2010-04-19  Corinna Vinschen  <corinna@vinschen.de>
+
        * syscalls.cc (rename): On STATUS_ACCESS_VIOLATION, retry to open
        for DELETE until the STATUS_ACCESS_VIOLATION goes away.  Add comment
        to explain why.
index 2076ac9..67f9b41 100644 (file)
@@ -297,7 +297,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
       int rcv = 0, len = sizeof (int);
 
       if (handle_to_fn (handle, name))
-       /* ok */;
+       dev.parse (name);
       else if (strcmp (name, ":sock:") == 0
               /* On NT4, NtQueryObject returns STATUS_NOT_IMPLEMENTED when
                  called for a socket handle. */
@@ -313,8 +313,6 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
        dev = *piper_dev;
       else
        dev = *pipew_dev;
-      if (name[0])
-       access = FILE_CREATE_PIPE_INSTANCE;
     }
   else if (GetConsoleScreenBufferInfo (handle, &buf))
     {
@@ -361,8 +359,22 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
            }
        }
 
+      IO_STATUS_BLOCK io;
+      FILE_ACCESS_INFORMATION fai;
+
+      /* Console windows are not kernel objects, so the access mask returned
+        by NtQueryInformationFile is meaningless. */
       if (dev == FH_TTY || dev == FH_CONSOLE)
        access |= GENERIC_READ | GENERIC_WRITE;
+      else if (NT_SUCCESS (NtQueryInformationFile (handle, &io, &fai,
+                                                  sizeof fai,
+                                                  FileAccessInformation)))
+       {
+         if (fai.AccessFlags & FILE_READ_DATA)
+           access |= GENERIC_READ;
+         if (fai.AccessFlags & FILE_WRITE_DATA)
+           access |= GENERIC_WRITE;
+       }
       else if (fd == 0)
        access |= GENERIC_READ;
       else