aboutsummaryrefslogtreecommitdiff
path: root/lockfiles.lua
diff options
context:
space:
mode:
authorAlin Mr <almr.oss@outlook.com>2024-05-03 11:08:09 +0000
committerFlorian Fischer <florian.fischer@muhq.space>2024-05-03 16:46:25 +0200
commitdce094a0c6730ae47d27e90a84d2f582aba42736 (patch)
treee31823bb723975bcd085399bbeea46e37fa0be47 /lockfiles.lua
parentf6919f7f59b8f9f25c7b8c08df4d6f1c2c1850dd (diff)
downloadvis-lockfiles-dce094a0c6730ae47d27e90a84d2f582aba42736.tar.gz
vis-lockfiles-dce094a0c6730ae47d27e90a84d2f582aba42736.zip
lockfiles.lua: fix fd leak
Diffstat (limited to 'lockfiles.lua')
-rw-r--r--lockfiles.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/lockfiles.lua b/lockfiles.lua
index 9e120bd..d018bc9 100644
--- a/lockfiles.lua
+++ b/lockfiles.lua
@@ -53,10 +53,12 @@ local function create_lock_file(lock_dir, lfile_path)
end
-- create the lock file with our pid
- if not io.open(lfile_path, 'w') then
+ lock_file = io.open(lfile_path, 'w')
+ if not lock_file then
+ -- retry, this time asserting success; first ensure directory exists
assert(os.execute('mkdir -p "' .. lock_dir .. '"'))
+ lock_file = assert(io.open(lfile_path, 'w'))
end
- lock_file = assert(io.open(lfile_path, 'w'))
lock_file:write(vis_pid)
lock_file:close()