Honour the inheritance of a handle if it would be duplicated or opened.
authorHartmut Birr <osexpert@googlemail.com>
Thu, 11 Aug 2005 19:37:29 +0000 (19:37 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Thu, 11 Aug 2005 19:37:29 +0000 (19:37 +0000)
svn path=/trunk/; revision=17295

reactos/lib/crt/io/dup.c
reactos/lib/crt/io/open.c

index 0404971..ed5a1c0 100644 (file)
@@ -13,25 +13,27 @@ int _dup(int handle)
   HANDLE hProcess = GetCurrentProcess();
   BOOL result;
   int fd;
+  int mode;
 
   hFile = (HANDLE)_get_osfhandle(handle);
        if (hFile == INVALID_HANDLE_VALUE) {
                __set_errno(EBADF);
                return -1;
        }
+  mode = __fileno_getmode(handle);
   result = DuplicateHandle(hProcess,
                           hFile,
                           hProcess,
                           &hFile,
                           0,
-                          TRUE,
+                           mode & FNOINHERIT ? FALSE : TRUE,
                           DUPLICATE_SAME_ACCESS);
        if (result == FALSE) {
                _dosmaperr(GetLastError());
                return -1;
        }
 
-  fd = alloc_fd(hFile, __fileno_getmode(handle));
+  fd = alloc_fd(hFile, mode);
   if (fd < 0)
   {
          CloseHandle(hFile);
index c32304c..b59623f 100644 (file)
@@ -523,7 +523,7 @@ int __fileno_dup2(int handle1, int handle2)
                 hProcess,
                 &fdinfo(handle2)->hFile,
                 0,
-                TRUE,
+                fdinfo(handle1)->fdflags & FNOINHERIT ? FALSE : TRUE,
                 DUPLICATE_SAME_ACCESS);
    if (result) {
 //      _pioinfo[handle2]->fd = handle2;