Index: trunk/src/VBox/ValidationKit/common/utils.py
===================================================================
--- trunk/src/VBox/ValidationKit/common/utils.py	(revision 69111)
+++ trunk/src/VBox/ValidationKit/common/utils.py	(revision 69443)
@@ -45,7 +45,9 @@
 if sys.platform == 'win32':
     import ctypes;
+    import msvcrt;              # pylint: disable=import-error
     import win32api;            # pylint: disable=import-error
     import win32con;            # pylint: disable=import-error
     import win32console;        # pylint: disable=import-error
+    import win32file;           # pylint: disable=import-error
     import win32process;        # pylint: disable=import-error
 else:
@@ -288,4 +290,69 @@
                 return open(sFile, sMode + 'N');
             return open(sFile, sMode[:offComma] + 'N' + sMode[offComma:]);
+
+        # Just in case.
+        return open(sFile, sMode);
+
+    oFile = open(sFile, sMode)
+    #try:
+    fcntl(oFile, F_SETFD, fcntl(oFile, F_GETFD) | FD_CLOEXEC);
+    #except:
+    #    pass;
+    return oFile;
+
+def openNoDenyDeleteNoInherit(sFile, sMode = 'r'):
+    """
+    Wrapper around open() that tries it's best to make sure the file isn't
+    inherited by child processes.
+
+    This is a best effort thing at the moment as it doesn't synchronizes with
+    child process spawning in any way.  Thus it can be subject to races in
+    multithreaded programs.
+    """
+
+    try:
+        from fcntl import FD_CLOEXEC, F_GETFD, F_SETFD, fcntl; # pylint: disable=F0401
+    except:
+        if getHostOs() == 'win':
+            # Need to use CreateFile directly to open the file so we can feed it FILE_SHARE_DELETE.
+            fAccess = 0;
+            fDisposition = win32file.OPEN_EXISTING;                                                 # pylint: disable=no-member
+            if 'r' in sMode or '+' in sMode:
+                fAccess |= win32file.GENERIC_READ;                                                  # pylint: disable=no-member
+            if 'a' in sMode:
+                fAccess |= win32file.GENERIC_WRITE;                                                 # pylint: disable=no-member
+                fDisposition = win32file.OPEN_ALWAYS;                                               # pylint: disable=no-member
+            elif 'w' in sMode:
+                fAccess = win32file.GENERIC_WRITE;                                                  # pylint: disable=no-member
+                if '+' in sMode:
+                    fDisposition = win32file.OPEN_ALWAYS;                                           # pylint: disable=no-member
+                    fAccess |= win32file.GENERIC_READ;                                              # pylint: disable=no-member
+                else:
+                    fDisposition = win32file.CREATE_ALWAYS;                                         # pylint: disable=no-member
+            if not fAccess:
+                fAccess |= win32file.GENERIC_READ;                                                  # pylint: disable=no-member
+            fSharing = (win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE                      # pylint: disable=no-member
+                        | win32file.FILE_SHARE_DELETE);                                             # pylint: disable=no-member
+            hFile = win32file.CreateFile(sFile, fAccess, fSharing, None, fDisposition, 0, None);    # pylint: disable=no-member
+            if 'a' in sMode:
+                win32file.SetFilePointer(hFile, 0, win32file.FILE_END);                             # pylint: disable=no-member
+
+            # Turn the NT handle into a CRT file descriptor.
+            hDetachedFile = hFile.Detach();
+            if fAccess == win32file.GENERIC_READ:                                                   # pylint: disable=no-member
+                fOpen = os.O_RDONLY;
+            elif fAccess == win32file.GENERIC_WRITE:                                                # pylint: disable=no-member
+                fOpen = os.O_WRONLY;
+            else:
+                fOpen = os.O_RDWR;
+            if 'a' in sMode:
+                fOpen |= os.O_APPEND;
+            if 'b' in sMode or 't' in sMode:
+                fOpen |= os.O_TEXT;
+            fdFile = msvcrt.open_osfhandle(hDetachedFile, fOpen);
+
+            # Tell python to use this handle.
+            return os.fdopen(fdFile, sMode);
+
         # Just in case.
         return open(sFile, sMode);
