* Fix race in creating temp directories pre-fork (#16965)
* These can still race when multiple ansible processes are created at the same time. * Reverse order of expanduser and expandvars in unfrakpath(). So that tildes in environment variables will be handled.
This commit is contained in:
parent
746ea64d30
commit
1ecf51d87e
2 changed files with 3 additions and 2 deletions
|
@ -28,6 +28,7 @@ from ansible.compat.six.moves import configparser
|
||||||
|
|
||||||
from ansible.parsing.quoting import unquote
|
from ansible.parsing.quoting import unquote
|
||||||
from ansible.errors import AnsibleOptionsError
|
from ansible.errors import AnsibleOptionsError
|
||||||
|
from ansible.utils.path import makedirs_safe
|
||||||
|
|
||||||
BOOL_TRUE = frozenset([ "true", "t", "y", "1", "yes", "on" ])
|
BOOL_TRUE = frozenset([ "true", "t", "y", "1", "yes", "on" ])
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ def get_config(p, section, key, env_var, default, boolean=False, integer=False,
|
||||||
elif istmppath:
|
elif istmppath:
|
||||||
value = shell_expand(value)
|
value = shell_expand(value)
|
||||||
if not os.path.exists(value):
|
if not os.path.exists(value):
|
||||||
os.makedirs(value, 0o700)
|
makedirs_safe(value, 0o700)
|
||||||
prefix = 'ansible-local-%s' % os.getpid()
|
prefix = 'ansible-local-%s' % os.getpid()
|
||||||
value = tempfile.mkdtemp(prefix=prefix, dir=value)
|
value = tempfile.mkdtemp(prefix=prefix, dir=value)
|
||||||
elif ispathlist:
|
elif ispathlist:
|
||||||
|
|
|
@ -31,7 +31,7 @@ def unfrackpath(path):
|
||||||
example:
|
example:
|
||||||
'$HOME/../../var/mail' becomes '/var/spool/mail'
|
'$HOME/../../var/mail' becomes '/var/spool/mail'
|
||||||
'''
|
'''
|
||||||
return os.path.normpath(os.path.realpath(os.path.expandvars(os.path.expanduser(to_bytes(path, errors='strict')))))
|
return os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(to_bytes(path, errors='strict')))))
|
||||||
|
|
||||||
def makedirs_safe(path, mode=None):
|
def makedirs_safe(path, mode=None):
|
||||||
'''Safe way to create dirs in muliprocess/thread environments'''
|
'''Safe way to create dirs in muliprocess/thread environments'''
|
||||||
|
|
Loading…
Reference in a new issue