fix '/var/lock' non-existent throw traceback
authorGui Chen <gui.chen@intel.com>
Wed, 15 May 2013 07:18:22 +0000 (03:18 -0400)
committerGui Chen <gui.chen@intel.com>
Wed, 15 May 2013 08:01:35 +0000 (04:01 -0400)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/chroot.py
mic/utils/fs_related.py

index 546c0c8..99fb9a2 100644 (file)
@@ -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))
index e4e5c50..06e9d84 100644 (file)
@@ -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