From 7bd91288486c552ddec136b005a427bed933aa33 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 4 Aug 2016 16:35:36 -0700 Subject: [PATCH] * 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. (cherry picked from commit 1ecf51d87e90e877cce387c738f1496eba2da93c) --- lib/ansible/constants.py | 3 ++- lib/ansible/utils/path.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index a1a26b70f31..0c4025ab27c 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -28,6 +28,7 @@ from ansible.compat.six.moves import configparser from ansible.parsing.quoting import unquote from ansible.errors import AnsibleOptionsError +from ansible.utils.path import makedirs_safe # copied from utils, avoid circular reference fun :) def mk_boolean(value): @@ -75,7 +76,7 @@ def get_config(p, section, key, env_var, default, boolean=False, integer=False, elif istmppath: value = shell_expand(value) if not os.path.exists(value): - os.makedirs(value, 0o700) + makedirs_safe(value, 0o700) prefix = 'ansible-local-%s' % os.getpid() value = tempfile.mkdtemp(prefix=prefix, dir=value) elif ispathlist: diff --git a/lib/ansible/utils/path.py b/lib/ansible/utils/path.py index 1fe62e85940..a89dc0a95b3 100644 --- a/lib/ansible/utils/path.py +++ b/lib/ansible/utils/path.py @@ -30,7 +30,7 @@ def unfrackpath(path): example: '$HOME/../../var/mail' becomes '/var/spool/mail' ''' - return os.path.normpath(os.path.realpath(os.path.expandvars(os.path.expanduser(path)))) + return os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(path)))) def makedirs_safe(path, mode=None): '''Safe way to create dirs in muliprocess/thread environments'''