summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/gui/anonvpn.py2
-rw-r--r--src/leap/bitmask/gui/app.py12
-rw-r--r--src/leap/bitmask/gui/app2.py8
-rw-r--r--src/leap/bitmask/gui/housekeeping.py17
4 files changed, 35 insertions, 4 deletions
diff --git a/src/leap/bitmask/gui/anonvpn.py b/src/leap/bitmask/gui/anonvpn.py
index 7912085e..5b3443d8 100644
--- a/src/leap/bitmask/gui/anonvpn.py
+++ b/src/leap/bitmask/gui/anonvpn.py
@@ -32,6 +32,7 @@ from multiprocessing import Process
from leap.bitmask.core.launcher import run_bitmaskd, pid
from leap.bitmask.gui.housekeeping import cleanup, terminate, reset_authtoken
+from leap.bitmask.gui.housekeeping import check_stale_pidfile
from leap.bitmask.gui.housekeeping import NoAuthTokenError
from leap.common.config import get_path_prefix
@@ -59,6 +60,7 @@ def launch_gui():
def start_app():
global bitmaskd
+ check_stale_pidfile()
bitmaskd = Process(target=run_bitmaskd)
bitmaskd.start()
reset_authtoken()
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index eb34f398..f22292b7 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -36,6 +36,7 @@ from leap.bitmask.gui.systray import WithTrayIcon
from leap.bitmask.gui.housekeeping import cleanup, terminate, reset_authtoken
from leap.bitmask.gui.housekeeping import get_authenticated_url
from leap.bitmask.gui.housekeeping import NoAuthTokenError
+from leap.bitmask.gui.housekeeping import check_stale_pidfile
from leap.common.config import get_path_prefix
@@ -195,16 +196,21 @@ def _handle_kill(*args, **kw):
closing = True
+def launch_backend():
+ global bitmaskd
+ check_stale_pidfile()
+ bitmaskd = Process(target=run_bitmaskd)
+ bitmaskd.start()
+
+
def launch_gui(with_window=True):
global qApp
- global bitmaskd
global browser
if IS_WIN:
freeze_support()
- bitmaskd = Process(target=run_bitmaskd)
- bitmaskd.start()
+ launch_backend()
qApp = QApplication([])
try:
browser = BrowserWindow(None)
diff --git a/src/leap/bitmask/gui/app2.py b/src/leap/bitmask/gui/app2.py
index f8f62938..151dead5 100644
--- a/src/leap/bitmask/gui/app2.py
+++ b/src/leap/bitmask/gui/app2.py
@@ -120,12 +120,18 @@ class BrowserWindow(object):
print('[bitmask] shutting down gui')
-def launch_gui():
+def launch_backend():
global bitmaskd
+ check_stale_pidfile()
bitmaskd = Process(target=run_bitmaskd)
bitmaskd.start()
+
+def launch_gui():
+
+ launch_backend()
+
# there are some tricky movements here to synchronize
# the different closing events:
diff --git a/src/leap/bitmask/gui/housekeeping.py b/src/leap/bitmask/gui/housekeeping.py
index 5c1d8079..b6c29b47 100644
--- a/src/leap/bitmask/gui/housekeeping.py
+++ b/src/leap/bitmask/gui/housekeeping.py
@@ -2,6 +2,8 @@ import os
import signal
import time
+import psutil
+
from leap.common.config import get_path_prefix
@@ -44,6 +46,21 @@ def reset_authtoken():
pass
+def check_stale_pidfile():
+
+ def is_pid_running(pidno):
+ return 1 == len(filter(lambda p: p.pid == int(pidno), psutil.process_iter()))
+
+ pidno = None
+ pidfile = os.path.join(get_path_prefix(), 'leap', 'bitmaskd.pid')
+ if os.path.isfile(pidfile):
+ with open(pidfile, 'r') as pid_fd:
+ pidno = pid_fd.readline().strip()
+ if pidno and pidno.isdigit():
+ if not is_pid_running(pidno):
+ os.unlink(pidfile)
+
+
def cleanup():
print('[bitmask] cleaning up files')
base = os.path.join(get_path_prefix(), 'leap')