aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlin Mr <almr.oss@outlook.com>2024-05-03 14:06:49 +0000
committerFlorian Fischer <florian.fischer@muhq.space>2024-05-03 17:17:41 +0200
commit202c025eb7b066cc16d43bef5fb3d2574c84c45a (patch)
tree87a03d879882437e8d8dc08af8341138fd23a602
parent69dacf7f0e45b6e4fa0e6a20c01ae9caa55cb9e6 (diff)
downloadvis-lockfiles-202c025eb7b066cc16d43bef5fb3d2574c84c45a.tar.gz
vis-lockfiles-202c025eb7b066cc16d43bef5fb3d2574c84c45a.zip
lockfiles.lua: only check /proc/lock_pid if exists
-rw-r--r--lockfiles.lua15
1 files changed, 10 insertions, 5 deletions
diff --git a/lockfiles.lua b/lockfiles.lua
index 075150d..2c3cdea 100644
--- a/lockfiles.lua
+++ b/lockfiles.lua
@@ -32,11 +32,13 @@ end
-- determine vis' pid
local vis_pid
+local has_proc_fs_stat = false
do
local vis_proc_file = io.open('/proc/self/stat', 'r')
if vis_proc_file then
vis_pid = vis_proc_file:read('*n')
vis_proc_file:close()
+ has_proc_fs_stat = true
else -- fallback if /proc/self/stat is not available
local out = capture_cmd('sh -c "echo $PPID"')
@@ -46,12 +48,15 @@ end
assert(vis_pid)
local function pid_lives(pid)
- local tst = io.open('/proc/' .. pid .. '/stat')
- if tst then
- tst:close()
- return true
+ if has_proc_fs_stat then
+ local tst = io.open('/proc/' .. pid .. '/stat')
+ if tst then
+ tst:close()
+ else
+ return false
+ end
end
- return false
+ return true
end
-- returns PID owning lock (possibly vis_pid)