From 96ba208a00617c462cbdd2802a3c97bc6ebb28f3 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 14 Feb 2018 00:14:21 +0100 Subject: [bug] remove stale pidfile - Resolves: #9229 --- src/leap/bitmask/gui/housekeeping.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/leap/bitmask/gui/housekeeping.py') 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') -- cgit v1.2.3