From f9a3cce2f52e249c0b836050a7f408f77e7d74c9 Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Fri, 19 Jun 2015 01:41:27 +0530 Subject: geo-rep: Fix fd referenced before assignment Fix fd reference before assignment in mgmt_lock function. BUG: 1240607 Change-Id: Ib8a5207a516eecb55a5f906ff5d49abc98cab2a6 Reviewed-on: http://review.gluster.org/11318 Signed-off-by: Kotresh HR Reviewed-on: http://review.gluster.org/11563 Tested-by: Gluster Build System Tested-by: NetBSD Build System Reviewed-by: Saravanakumar Arumugam Reviewed-by: Milind Changire Reviewed-by: Venky Shankar --- geo-replication/syncdaemon/master.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'geo-replication') diff --git a/geo-replication/syncdaemon/master.py b/geo-replication/syncdaemon/master.py index 37be4fc3adc..5b8abc5fd9f 100644 --- a/geo-replication/syncdaemon/master.py +++ b/geo-replication/syncdaemon/master.py @@ -442,6 +442,7 @@ class GMasterCommon(object): def mgmt_lock(self): """Take management volume lock """ + fd = None bname = str(self.uuid) + "_" + str(gconf.slave_id) + "_subvol_" \ + str(gconf.subvol_num) + ".lock" mgmt_lock_dir = os.path.join(gconf.meta_volume_mnt, "geo-rep") @@ -455,18 +456,21 @@ class GMasterCommon(object): logging.info("Creating geo-rep directory in meta volume...") try: os.makedirs(mgmt_lock_dir) - fd = os.open(path, os.O_CREAT | os.O_RDWR) except OSError: ex = sys.exc_info()[1] if ex.errno == EEXIST: pass else: raise + fd = os.open(path, os.O_CREAT | os.O_RDWR) + else: + raise try: fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) except: ex = sys.exc_info()[1] - os.close(fd) + if fd: + os.close(fd) if isinstance(ex, IOError) and ex.errno in (EACCES, EAGAIN): # cannot grab, it's taken logging.debug("Lock held by someother worker process") -- cgit