From 56e65db9e0608555d1852fc546b482f6a93cfc80 Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 13:36:36 +0000 Subject: lockfiles.lua: check if locking pid exists --- lockfiles.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lockfiles.lua b/lockfiles.lua index e223e10..075150d 100644 --- a/lockfiles.lua +++ b/lockfiles.lua @@ -45,6 +45,15 @@ do end assert(vis_pid) +local function pid_lives(pid) + local tst = io.open('/proc/' .. pid .. '/stat') + if tst then + tst:close() + return true + end + return false +end + -- returns PID owning lock (possibly vis_pid) local function create_lock_file(lock_dir, lfile_path) local lock_pid @@ -52,7 +61,9 @@ local function create_lock_file(lock_dir, lfile_path) if lock_file then lock_pid = lock_file:read('*n') lock_file:close() - return lock_pid + if lock_pid == vis_pid or pid_lives(lock_pid) then + return lock_pid + end end -- create the lock file with our pid -- cgit v1.2.3