diff options
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 |
