aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua18
1 files changed, 11 insertions, 7 deletions
diff --git a/init.lua b/init.lua
index ff38679..8b8a8c6 100644
--- a/init.lua
+++ b/init.lua
@@ -75,18 +75,19 @@ end
local created_locks = {}
local function create_lock_file(lfile_path)
- local already_locked = os.execute('test -e ' .. '"' .. lfile_path .. '"')
- if already_locked then
+ local lock_file = io.open(lfile_path)
+ if lock_file then
+ lock_file:close()
return false
end
-- create the lock file with our pid
- local cmd = 'echo ' .. vis_pid .. ' > "' .. lfile_path .. '"'
- assert(os.execute(cmd))
+ lock_file = assert(io.open(lfile_path, 'w'))
+ lock_file:write(vis_pid)
+ lock_file:close()
-- detect a possible race
- local lock_file = io.open(lfile_path)
- assert(lock_file)
+ lock_file = assert(io.open(lfile_path))
local lock_pid = lock_file:read('*n')
lock_file:close()
local locked = tonumber(lock_pid) == vis_pid
@@ -100,7 +101,10 @@ local function create_lock_file(lfile_path)
end
local function delete_lock_file(lfile_path)
- os.execute('rm ' .. '"' .. lfile_path .. '"')
+ local success, err = os.remove(lfile_path)
+ if not success then
+ vis:info('vis-lockfiles: ' .. err)
+ end
created_locks[lfile_path] = nil
end