From 2babe2e0ff4fd0caefe41cff946f9d625e6936c2 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 1 Mar 2018 19:13:40 +0100 Subject: [bug] catch errors while cleaning up --- src/leap/bitmask/gui/housekeeping.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/leap/bitmask') diff --git a/src/leap/bitmask/gui/housekeeping.py b/src/leap/bitmask/gui/housekeeping.py index b6c29b47..5d549619 100644 --- a/src/leap/bitmask/gui/housekeeping.py +++ b/src/leap/bitmask/gui/housekeeping.py @@ -49,16 +49,20 @@ def reset_authtoken(): def check_stale_pidfile(): def is_pid_running(pidno): - return 1 == len(filter(lambda p: p.pid == int(pidno), psutil.process_iter())) + 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) + try: + 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) + except Exception as exc: + print('[bitmask] Error while removing stale file: %r' % exc) def cleanup(): @@ -68,4 +72,7 @@ def cleanup(): pid = os.path.join(base, 'bitmaskd.pid') for _f in [token, pid]: if os.path.isfile(_f): - os.unlink(_f) + try: + os.unlink(_f) + except Exception: + pass -- cgit v1.2.3