aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlin Mr <almr.oss@outlook.com>2024-05-03 13:36:36 +0000
committerFlorian Fischer <florian.fischer@muhq.space>2024-05-03 17:17:40 +0200
commit56e65db9e0608555d1852fc546b482f6a93cfc80 (patch)
treee3bd8fc864390ac159c82515c180c2a0a620492c
parent526873bef425574974358b7f26975cdd7d7cdd1b (diff)
downloadvis-lockfiles-56e65db9e0608555d1852fc546b482f6a93cfc80.tar.gz
vis-lockfiles-56e65db9e0608555d1852fc546b482f6a93cfc80.zip
lockfiles.lua: check if locking pid exists
-rw-r--r--lockfiles.lua13
1 files changed, 12 insertions, 1 deletions
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