From 4316f75e1b905c5b0fab33c9940f2214de2344d8 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Wed, 15 May 2013 03:18:22 -0400 Subject: [PATCH] fix '/var/lock' non-existent throw traceback Signed-off-by: Gui Chen --- mic/chroot.py | 2 ++ mic/utils/fs_related.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mic/chroot.py b/mic/chroot.py index 546c0c8..99fb9a2 100644 --- a/mic/chroot.py +++ b/mic/chroot.py @@ -142,6 +142,8 @@ def setup_chrootenv(chrootdir, bindmounts = None, mountparent = True): """Default bind mounts""" for pt in BIND_MOUNTS: + if not os.path.exists(pt): + continue chrootmounts.append(fs_related.BindChrootMount(pt, chrootdir, None)) diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index e4e5c50..06e9d84 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -949,10 +949,15 @@ class LoopDevice(object): os.unlink(self.device) DEVICE_PIDFILE_DIR = "/var/tmp/mic/device" +DEVICE_LOCKFILE = "/var/lock/__mic_loopdev.lock" def get_loop_device(losetupcmd, lofile): + global DEVICE_PIDFILE_DIR + global DEVICE_LOCKFILE + import fcntl - fp = open("/var/lock/__mic_loopdev.lock", 'w') + makedirs(os.path.dirname(DEVICE_LOCKFILE)) + fp = open(DEVICE_LOCKFILE, 'w') fcntl.flock(fp, fcntl.LOCK_EX) try: loopdev = None @@ -993,7 +998,7 @@ def get_loop_device(losetupcmd, lofile): try: fcntl.flock(fp, fcntl.LOCK_UN) fp.close() - os.unlink('/var/lock/__mic_loopdev.lock') + os.unlink(DEVICE_LOCKFILE) except: pass -- 2.7.4