Skip to content

Commit

Permalink
Re-open lock file before locking
Browse files Browse the repository at this point in the history
because the previous 'withlock' cleanup function might have deleted
the file and since we still held a handle to the old deleted file,
we could run concurrently with a 3rd 'withlock' which creates a new file.

Fixes poeml#1
Fixes boo#864785

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
  • Loading branch information
bmwiedemann committed Jan 1, 2023
1 parent 6ffda60 commit 218831d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions withlock
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ def main():

prev_umask = os.umask(0o066)

lock = open(lockfile, 'w')

global got_lock
while 1 + 1 == 2:

try:
lock = open(lockfile, 'w')
fcntl.lockf(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
got_lock = True
break
Expand Down

0 comments on commit 218831d

Please sign in to comment.