From 10766995ec5914247c21694062337c22e83e1dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 17 Sep 2012 13:19:18 +0100 Subject: [PATCH] fix cleanup_file_locks with restricted permissions SELinux was seen to disallow kill(pid, 0). Therefore ensure that the pid is determined to be still running if we get EPERM. Fixes bug: 1051924 Change-Id: Ib84e2fc460066ee03070b9bda15732cce573ccf3 --- nova/utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nova/utils.py b/nova/utils.py index 01a52b52ae3f..6535b06468a1 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -21,6 +21,7 @@ import contextlib import datetime +import errno import functools import hashlib import inspect @@ -1000,11 +1001,12 @@ def cleanup_file_locks(): {'filename': filename, 'pid': pid}) try: os.kill(int(pid), 0) - except OSError, e: - # PID wasn't found - delete_if_exists(os.path.join(FLAGS.lock_path, filename)) - LOG.debug(_('Cleaned sentinel %(filename)s for pid %(pid)s') % - {'filename': filename, 'pid': pid}) + except OSError as e: + if e.errno == errno.ESRCH: + # PID wasn't found + delete_if_exists(os.path.join(FLAGS.lock_path, filename)) + LOG.debug(_('Cleaned sentinel %(filename)s for pid %(pid)s') % + {'filename': filename, 'pid': pid}) # cleanup lock files for filename in files: @@ -1013,8 +1015,8 @@ def cleanup_file_locks(): continue try: stat_info = os.stat(os.path.join(FLAGS.lock_path, filename)) - except OSError as (errno, strerror): - if errno == 2: # doesn't exist + except OSError as e: + if e.errno == errno.ENOENT: continue else: raise @@ -1033,8 +1035,8 @@ def delete_if_exists(pathname): try: os.unlink(pathname) - except OSError as (errno, strerror): - if errno == 2: # doesn't exist + except OSError as e: + if e.errno == errno.ENOENT: return else: raise