mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Open LOG_LOCK file with FD_CLOEXEC to prevent file descriptor leakage
Fixes #5399
This commit is contained in:
parent
bbda98a3ee
commit
3f90020d62
1 changed files with 10 additions and 3 deletions
|
@ -74,12 +74,19 @@ def get_cowsay_info():
|
|||
cowsay, noncow = get_cowsay_info()
|
||||
|
||||
def log_lockfile():
|
||||
# create the path for the lockfile and open it
|
||||
tempdir = tempfile.gettempdir()
|
||||
uid = os.getuid()
|
||||
path = os.path.join(tempdir, ".ansible-lock.%s" % uid)
|
||||
return path
|
||||
|
||||
LOG_LOCK = open(log_lockfile(), 'w')
|
||||
lockfile = open(path, 'w')
|
||||
# use fcntl to set FD_CLOEXEC on the file descriptor,
|
||||
# so that we don't leak the file descriptor later
|
||||
lockfile_fd = lockfile.fileno()
|
||||
old_flags = fcntl.fcntl(lockfile_fd, fcntl.F_GETFD)
|
||||
fcntl.fcntl(lockfile_fd, fcntl.F_SETFD, old_flags | fcntl.FD_CLOEXEC)
|
||||
return lockfile
|
||||
|
||||
LOG_LOCK = log_lockfile()
|
||||
|
||||
def log_flock(runner):
|
||||
if runner is not None:
|
||||
|
|
Loading…
Reference in a new issue