diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index 5f4e7292..4c88fd8b 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -23,7 +23,6 @@ # import datetime -import fcntl import lxml.etree import os import os.path @@ -1243,9 +1242,7 @@ class QubesVm(object): try: old_umask = os.umask(002) with open(self.firewall_conf, 'w') as f: - fcntl.lockf(f, fcntl.LOCK_EX) tree.write(f, encoding="UTF-8", pretty_print=True) - fcntl.lockf(f, fcntl.LOCK_UN) f.close() os.umask(old_umask) except EnvironmentError as err: diff --git a/core/qubes.py b/core/qubes.py index 3f983f58..d369b37b 100755 --- a/core/qubes.py +++ b/core/qubes.py @@ -28,12 +28,19 @@ import os import os.path import lxml.etree import xml.parsers.expat -import fcntl import time import warnings import tempfile import grp import atexit +if os.name == 'posix': + import fcntl +elif os.name == 'nt': + import win32con + import win32file + import pywintypes +else: + raise RuntimeError, "Qubes works only on POSIX or WinNT systems" # Do not use XenAPI or create/read any VM files # This is for testing only! @@ -579,7 +586,12 @@ class QubesVmCollection(dict): # still the right file while True: self.qubes_store_file = open (self.qubes_store_filename, 'r') - fcntl.lockf(self.qubes_store_file, fcntl.LOCK_SH) + if os.name == 'posix': + fcntl.lockf (self.qubes_store_file, fcntl.LOCK_SH) + elif os.name == 'nt': + overlapped = pywintypes.OVERLAPPED() + win32file.LockFileEx(win32file._get_osfhandle(self.qubes_store_file.fileno()), + 0, 0, -0x10000, overlapped) if os.fstat(self.qubes_store_file.fileno()) == os.stat( self.qubes_store_filename): break @@ -591,7 +603,12 @@ class QubesVmCollection(dict): # still the right file while True: self.qubes_store_file = open (self.qubes_store_filename, 'r+') - fcntl.lockf(self.qubes_store_file, fcntl.LOCK_EX) + if os.name == 'posix': + fcntl.lockf (self.qubes_store_file, fcntl.LOCK_EX) + elif os.name == 'nt': + overlapped = pywintypes.OVERLAPPED() + win32file.LockFileEx(win32file._get_osfhandle(self.qubes_store_file.fileno()), + win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, -0x10000, overlapped) if os.fstat(self.qubes_store_file.fileno()) == os.stat( self.qubes_store_filename): break