summaryrefslogtreecommitdiff
path: root/src/leap/bitmask
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask')
-rw-r--r--src/leap/bitmask/gui/eip_status.py3
-rw-r--r--src/leap/bitmask/gui/mainwindow.py29
-rw-r--r--src/leap/bitmask/platform_init/initializers.py7
-rw-r--r--src/leap/bitmask/platform_init/locks.py59
4 files changed, 66 insertions, 32 deletions
diff --git a/src/leap/bitmask/gui/eip_status.py b/src/leap/bitmask/gui/eip_status.py
index abd6e2c9..1c167335 100644
--- a/src/leap/bitmask/gui/eip_status.py
+++ b/src/leap/bitmask/gui/eip_status.py
@@ -303,7 +303,6 @@ class EIPStatusWidget(QtGui.QWidget):
"""
# XXX this name is unfortunate. "disable" is also applied to a
# pushbutton being grayed out.
-
logger.debug('Hiding EIP start button')
# you might be tempted to change this for a .setEnabled(False).
# it won't work. it's under the claws of the state machine.
@@ -334,7 +333,7 @@ class EIPStatusWidget(QtGui.QWidget):
Triggered after a successful login.
Enables the start button.
"""
- # logger.debug('Showing EIP start button')
+ logger.debug('Showing EIP start button')
self.eip_button.show()
self.hide_eip_cancel_button()
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index e086d02a..653ebc35 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -48,6 +48,7 @@ from leap.bitmask.gui.wizard import Wizard
from leap.bitmask.gui.providers import Providers
from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX
+from leap.bitmask.platform_init import locks
from leap.bitmask.platform_init.initializers import init_platform
from leap.bitmask.platform_init.initializers import init_signals
@@ -63,10 +64,6 @@ from leap.bitmask.util import autostart, make_address
from leap.bitmask.util.keyring_helpers import has_keyring
from leap.bitmask.logs.leap_log_handler import LeapLogHandler
-if IS_WIN:
- from leap.bitmask.platform_init.locks import WindowsLock
- from leap.bitmask.platform_init.locks import raise_window_ack
-
from leap.common.events import register
from leap.common.events import events_pb2 as proto
@@ -656,6 +653,10 @@ class MainWindow(QtGui.QMainWindow):
to do so, start it. Otherwise it leaves everything in place
for the user to click Turn ON.
"""
+ if self._eip_status.missing_helpers:
+ self._eip_status.disable_eip_start()
+ return
+
settings = self._settings
default_provider = settings.get_defaultprovider()
enabled_services = []
@@ -700,7 +701,9 @@ class MainWindow(QtGui.QMainWindow):
self._eip_status.disable_eip_start()
else:
self._eip_status.disable_eip_start()
- self._eip_status.set_eip_status(self.tr("Disabled"))
+ # NOTE: we shouldn't be setting the message here.
+ if not self._eip_status.missing_helpers:
+ self._eip_status.set_eip_status(self.tr("Disabled"))
# this state flag is responsible for deferring the login
# so we must update it, otherwise we're in a deadlock.
@@ -812,6 +815,15 @@ class MainWindow(QtGui.QMainWindow):
self._show_hide_unsupported_services()
+ # XXX - HACK, kind of...
+ # With the 1ms QTimer.singleShot call we schedule the call right after
+ # other signals waiting for the qt reactor to take control.
+ # That way, the method is called right after the EIP machines' signals.
+ # We need to wait until that happens because the state-machine
+ # controlled widget shows the 'Turn On' button and we want to do the
+ # changes to that button right after, not before.
+ QtDelayedCall(1, self._update_eip_enabled_status)
+
if self._wizard:
possible_username = self._wizard.get_username()
possible_password = self._wizard.get_password()
@@ -836,8 +848,6 @@ class MainWindow(QtGui.QMainWindow):
self._wizard = None
self._backend_connect(only_tracked=True)
else:
- self._update_eip_enabled_status()
-
domain = self._settings.get_provider()
if domain is not None:
self._providers.select_provider_by_name(domain)
@@ -1852,7 +1862,7 @@ class MainWindow(QtGui.QMainWindow):
Callback for the raise window event
"""
if IS_WIN:
- raise_window_ack()
+ locks.raise_window_ack()
self.raise_window.emit()
@QtCore.Slot()
@@ -2009,7 +2019,6 @@ class MainWindow(QtGui.QMainWindow):
# Remove lockfiles on a clean shutdown.
logger.debug('Cleaning pidfiles')
- if IS_WIN:
- WindowsLock.release_all_locks()
+ locks.release_lock()
self.close()
diff --git a/src/leap/bitmask/platform_init/initializers.py b/src/leap/bitmask/platform_init/initializers.py
index f56b9330..6c62734c 100644
--- a/src/leap/bitmask/platform_init/initializers.py
+++ b/src/leap/bitmask/platform_init/initializers.py
@@ -164,6 +164,7 @@ def check_missing():
logger.debug(
"Setting alert_missing_scripts to False, we will not "
"ask again")
+ init_signals.eip_missing_helpers.emit()
config.set_alert_missing_scripts(False)
if complain_missing and missing_some:
@@ -171,6 +172,12 @@ def check_missing():
msg = _get_missing_complain_dialog(missing)
ret = msg.exec_()
+ # If there is some missing file and we don't want to complain, we emit the
+ # 'missing helpers' signal so the eip status can show that some files are
+ # missing.
+ if missing_some and not alert_missing and not complain_missing:
+ init_signals.eip_missing_helpers.emit()
+
#
# windows initializers
#
diff --git a/src/leap/bitmask/platform_init/locks.py b/src/leap/bitmask/platform_init/locks.py
index 78ebf4cd..ac45a5ce 100644
--- a/src/leap/bitmask/platform_init/locks.py
+++ b/src/leap/bitmask/platform_init/locks.py
@@ -22,11 +22,11 @@ import errno
import os
import platform
-from leap.bitmask import platform_init
+from leap.bitmask.platform_init import IS_WIN, IS_UNIX
from leap.common.events import signal as signal_event
from leap.common.events import events_pb2 as proto
-if platform_init.IS_UNIX:
+if IS_UNIX:
from fcntl import flock, LOCK_EX, LOCK_NB
else: # WINDOWS
import datetime
@@ -40,7 +40,7 @@ else: # WINDOWS
logger = logging.getLogger(__name__)
-if platform_init.IS_UNIX:
+if IS_UNIX:
class UnixLock(object):
"""
@@ -48,14 +48,13 @@ if platform_init.IS_UNIX:
See man 2 flock
"""
- def __init__(self, path):
+ _LOCK_FILE = '/tmp/bitmask.lock'
+
+ def __init__(self):
"""
- iniializes t he UnixLock with the path of the
- desired lockfile
+ Initialize the UnixLock.
"""
-
self._fd = None
- self.path = path
def get_lock(self):
"""
@@ -77,7 +76,7 @@ if platform_init.IS_UNIX:
:rtype: bool
"""
- self._fd = os.open(self.path, os.O_CREAT | os.O_RDWR)
+ self._fd = os.open(self._LOCK_FILE, os.O_CREAT | os.O_RDWR)
try:
flock(self._fd, LOCK_EX | LOCK_NB)
@@ -102,6 +101,21 @@ if platform_init.IS_UNIX:
gotit, pid = self._get_lock_and_pid()
return pid == os.getpid()
+ @classmethod
+ def release_lock(self):
+ """
+ Release the lock.
+
+ :return: True if the lock was released, False otherwise
+ :rtype: bool
+ """
+ try:
+ os.remove(self._LOCK_FILE)
+ return True
+ except Exception as e:
+ logger.debug("Problem removing lock, {0!r}".format(e))
+ return False
+
def _get_lock_and_pid(self):
"""
Tries to get a lock over the file.
@@ -109,7 +123,6 @@ if platform_init.IS_UNIX:
:rtype: tuple
"""
-
if self._get_lock():
self._write_to_pidfile()
return True, None
@@ -121,9 +134,7 @@ if platform_init.IS_UNIX:
Tries to read pid from the pidfile,
returns False if no content found.
"""
-
- pidfile = os.read(
- self._fd, 16)
+ pidfile = os.read(self._fd, 16)
if not pidfile:
return False
@@ -144,7 +155,7 @@ if platform_init.IS_UNIX:
os.fsync(fd)
-if platform_init.IS_WIN:
+if IS_WIN:
# Time to wait (in secs) before assuming a raise window signal has not been
# ack-ed.
@@ -348,17 +359,15 @@ def we_are_the_one_and_only():
:rtype: bool
"""
- _sys = platform.system()
-
- if _sys in ("Linux", "Darwin"):
- locker = UnixLock('/tmp/bitmask.lock')
+ if IS_UNIX:
+ locker = UnixLock()
locker.get_lock()
we_are_the_one = locker.locked_by_us
if not we_are_the_one:
signal_event(proto.RAISE_WINDOW)
return we_are_the_one
- elif _sys == "Windows":
+ elif IS_WIN:
locker = WindowsLock()
locker.get_lock()
we_are_the_one = locker.locked_by_us
@@ -398,6 +407,16 @@ def we_are_the_one_and_only():
else:
logger.warning("Multi-instance checker "
- "not implemented for %s" % (_sys))
+ "not implemented for %s" % (platform.system()))
# lies, lies, lies...
return True
+
+
+def release_lock():
+ """
+ Release the acquired lock.
+ """
+ if IS_WIN:
+ WindowsLock.release_all_locks()
+ elif IS_UNIX:
+ UnixLock.release_lock()