aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)