Changeset 69443 in vbox for trunk/src/VBox
- Timestamp:
- Oct 27, 2017 4:19:47 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 118778
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r69111 r69443 45 45 if sys.platform == 'win32': 46 46 import ctypes; 47 import msvcrt; # pylint: disable=import-error 47 48 import win32api; # pylint: disable=import-error 48 49 import win32con; # pylint: disable=import-error 49 50 import win32console; # pylint: disable=import-error 51 import win32file; # pylint: disable=import-error 50 52 import win32process; # pylint: disable=import-error 51 53 else: … … 288 290 return open(sFile, sMode + 'N'); 289 291 return open(sFile, sMode[:offComma] + 'N' + sMode[offComma:]); 292 293 # Just in case. 294 return open(sFile, sMode); 295 296 oFile = open(sFile, sMode) 297 #try: 298 fcntl(oFile, F_SETFD, fcntl(oFile, F_GETFD) | FD_CLOEXEC); 299 #except: 300 # pass; 301 return oFile; 302 303 def openNoDenyDeleteNoInherit(sFile, sMode = 'r'): 304 """ 305 Wrapper around open() that tries it's best to make sure the file isn't 306 inherited by child processes. 307 308 This is a best effort thing at the moment as it doesn't synchronizes with 309 child process spawning in any way. Thus it can be subject to races in 310 multithreaded programs. 311 """ 312 313 try: 314 from fcntl import FD_CLOEXEC, F_GETFD, F_SETFD, fcntl; # pylint: disable=F0401 315 except: 316 if getHostOs() == 'win': 317 # Need to use CreateFile directly to open the file so we can feed it FILE_SHARE_DELETE. 318 fAccess = 0; 319 fDisposition = win32file.OPEN_EXISTING; # pylint: disable=no-member 320 if 'r' in sMode or '+' in sMode: 321 fAccess |= win32file.GENERIC_READ; # pylint: disable=no-member 322 if 'a' in sMode: 323 fAccess |= win32file.GENERIC_WRITE; # pylint: disable=no-member 324 fDisposition = win32file.OPEN_ALWAYS; # pylint: disable=no-member 325 elif 'w' in sMode: 326 fAccess = win32file.GENERIC_WRITE; # pylint: disable=no-member 327 if '+' in sMode: 328 fDisposition = win32file.OPEN_ALWAYS; # pylint: disable=no-member 329 fAccess |= win32file.GENERIC_READ; # pylint: disable=no-member 330 else: 331 fDisposition = win32file.CREATE_ALWAYS; # pylint: disable=no-member 332 if not fAccess: 333 fAccess |= win32file.GENERIC_READ; # pylint: disable=no-member 334 fSharing = (win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE # pylint: disable=no-member 335 | win32file.FILE_SHARE_DELETE); # pylint: disable=no-member 336 hFile = win32file.CreateFile(sFile, fAccess, fSharing, None, fDisposition, 0, None); # pylint: disable=no-member 337 if 'a' in sMode: 338 win32file.SetFilePointer(hFile, 0, win32file.FILE_END); # pylint: disable=no-member 339 340 # Turn the NT handle into a CRT file descriptor. 341 hDetachedFile = hFile.Detach(); 342 if fAccess == win32file.GENERIC_READ: # pylint: disable=no-member 343 fOpen = os.O_RDONLY; 344 elif fAccess == win32file.GENERIC_WRITE: # pylint: disable=no-member 345 fOpen = os.O_WRONLY; 346 else: 347 fOpen = os.O_RDWR; 348 if 'a' in sMode: 349 fOpen |= os.O_APPEND; 350 if 'b' in sMode or 't' in sMode: 351 fOpen |= os.O_TEXT; 352 fdFile = msvcrt.open_osfhandle(hDetachedFile, fOpen); 353 354 # Tell python to use this handle. 355 return os.fdopen(fdFile, sMode); 356 290 357 # Just in case. 291 358 return open(sFile, sMode);
Note:
See TracChangeset
for help on using the changeset viewer.