From 202c025eb7b066cc16d43bef5fb3d2574c84c45a Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 14:06:49 +0000 Subject: lockfiles.lua: only check /proc/lock_pid if exists --- lockfiles.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lockfiles.lua') 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) -- cgit v1.2.3