qubes/vm/qubesvm: move is_guid_running to GUI extension

This commit is contained in:
Wojtek Porczyk 2016-04-19 15:59:25 +02:00
parent 341bbb4ef3
commit fe8fdb264b
2 changed files with 29 additions and 24 deletions

View File

@ -202,3 +202,25 @@ class GUI(qubes.ext.Extension):
pipe.stdin.write(''.join(monitor_layout))
pipe.stdin.close()
pipe.wait()
@staticmethod
def is_guid_running(vm):
'''Check whether gui daemon for this domain is available.
:returns: :py:obj:`True` if guid is running, \
:py:obj:`False` otherwise.
:rtype: bool
'''
xid = self.xid
if xid < 0:
return False
if not os.path.exists('/var/run/qubes/guid-running.{}'.format(xid)):
return False
return True
@qubes.ext.handler('domain-is-fully-usable')
def on_domain_is_fully_usable(self, vm, event):
if not self.is_guid_running(vm):
yield False

View File

@ -1312,21 +1312,6 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
and self.libvirt_domain.state() == libvirt.VIR_DOMAIN_PAUSED
def is_guid_running(self):
'''Check whether gui daemon for this domain is available.
:returns: :py:obj:`True` if guid is running, \
:py:obj:`False` otherwise.
:rtype: bool
'''
xid = self.xid
if xid < 0:
return False
if not os.path.exists('/var/run/qubes/guid-running.%d' % xid):
return False
return True
def is_qrexec_running(self):
'''Check whether qrexec for this domain is available.
@ -1340,21 +1325,19 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
def is_fully_usable(self):
return all(self.fire_event('domain-is-fully-usable'))
@qubes.events.handler('domain-is-fully-usable')
def on_domain_is_fully_usable(self, event):
'''Check whether domain is running and sane.
Currently this checks for running guid and qrexec.
:returns: :py:obj:`True` if qrexec is running, \
:py:obj:`False` otherwise.
:rtype: bool
Currently this checks for running qrexec.
'''
# Running gui-daemon implies also VM running
if not self.is_guid_running():
return False
if not self.is_qrexec_running():
return False
return True
yield False
# memory and disk