From c27a6b6c3ef8b2b529b884d261b2acabf6322077 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 14 Sep 2017 00:16:19 +0200 Subject: [feat] wait up to 20 seconds for polkit to be launched - Related: #9012 --- src/leap/bitmask/vpn/privilege.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py index 54065a81..458f690d 100644 --- a/src/leap/bitmask/vpn/privilege.py +++ b/src/leap/bitmask/vpn/privilege.py @@ -109,23 +109,29 @@ class LinuxPolicyChecker(object): :returns: a list of the paths where pkexec is to be found :rtype: list """ - if self._is_pkexec_in_system(): - if not self.is_up(): - self.launch() - time.sleep(2) - if self.is_up(): - pkexec_possibilities = which(self.PKEXEC_BIN) - if not pkexec_possibilities: - raise Exception("We couldn't find pkexec") - return pkexec_possibilities - else: - log.warn('No polkit auth agent found. pkexec ' + - 'will use its own auth agent.') - raise NoPolkitAuthAgentAvailable() - else: + if not self._is_pkexec_in_system(): log.warn('System has no pkexec') raise NoPkexecAvailable() + if not self.is_up(): + self.launch() + seconds = 0 + while not self.is_up(): + if seconds >= 20: + log.warn('No polkit auth agent found. pkexec ' + + 'will use its own auth agent.') + raise NoPolkitAuthAgentAvailable() + + # XXX: sleep()!!!! we should do it the twisted way + time.sleep(1) + seconds += 1 + + pkexec_possibilities = which(self.PKEXEC_BIN) + if not pkexec_possibilities: + raise Exception("We couldn't find pkexec") + + return pkexec_possibilities + @classmethod def launch(self): """ -- cgit v1.2.3