]> git.e2factory.org Git - e2factory.git/commitdiff
lock: log errors on cleanup, improve
authorTobias Ulmer <tu@emlix.com>
Thu, 21 Dec 2017 19:33:37 +0000 (20:33 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 10 Dec 2018 17:00:11 +0000 (18:00 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/lock.lua

index 80cbd578c666681660dc4053531d2dd85f62996f..2fda76c8557ad572957721814b2126c072c8c4bc 100644 (file)
@@ -45,7 +45,8 @@ end
 --- create a lock directory
 -- @param l table: lock object
 -- @param dir string: lock directory
--- @return boolean
+-- @return True on success, false on error.
+-- @return Err object on failure.
 function lock.lock(l, dir)
     local e = err.new("locking failed")
 
@@ -61,7 +62,8 @@ end
 --- remove a lock directory
 -- @param l table: lock object
 -- @param dir string: lock directory
--- @return boolean
+-- @return True on success, false on error.
+-- @return Err object on failure.
 function lock.unlock(l, dir)
     local e = err.new("unlocking failed")
     local rc, re
@@ -73,6 +75,8 @@ function lock.unlock(l, dir)
             if not rc then
                 return false, e:cat(re)
             end
+
+            break
         end
     end
 
@@ -82,9 +86,15 @@ end
 -- remove all remaining lock directories
 -- @param l table: lock object
 function lock.cleanup(l)
+    local rc, re
+
     while #l.locks > 0 do
-        lock.unlock(l, l.locks[1])
+        rc, re = lock.unlock(l, l.locks[1])
+        if not rc then
+            e2lib.logf(4, "unlocking lock failed: %s", re:tostring())
+        end
     end
+    e2lib.logf(4, "all locks released")
 end
 
 return strict.lock(lock)