qubes/app: automatically enable offline mode when running in chroot

Do not spray --offline-mode over every installer-related script.

QubesOS/qubes-issues#2412
This commit is contained in:
Marek Marczykowski-Górecki 2016-11-02 23:31:47 +01:00
parent d8a1216daf
commit c4e85a81fb
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 11 additions and 3 deletions

View File

@ -135,10 +135,18 @@ class VirConnectWrapper(object):
class VMMConnection(object):
'''Connection to Virtual Machine Manager (libvirt)'''
def __init__(self, offline_mode=False):
def __init__(self, offline_mode=None):
'''
:param offline_mode: enable/disable offline mode; default is to
enable when running in chroot as root, otherwise disable
'''
self._libvirt_conn = None
self._xs = None
self._xc = None
if offline_mode is None:
offline_mode = bool(os.getuid() == 0 and
os.stat('/') != os.stat('/proc/1/root/.'))
self._offline_mode = offline_mode
@property
@ -600,7 +608,7 @@ class Qubes(qubes.PropertyHolder):
default=True,
doc='check for updates inside qubes')
def __init__(self, store=None, load=True, offline_mode=False, lock=False,
def __init__(self, store=None, load=True, offline_mode=None, lock=False,
**kwargs):
#: logger instance for logging global messages
self.log = logging.getLogger('app')

View File

@ -333,7 +333,7 @@ class QubesArgumentParser(argparse.ArgumentParser):
self.add_argument('--qubesxml', metavar='FILE', action='store',
dest='app', help=argparse.SUPPRESS)
self.add_argument('--offline-mode', action='store_true',
default=False, dest='offline_mode', help=argparse.SUPPRESS)
default=None, dest='offline_mode', help=argparse.SUPPRESS)
self.add_argument('--verbose', '-v', action='count',