From 507b56d0f0a5d94b0d62aea2515e04834bdf39ba Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Fri, 26 Jul 2019 09:52:53 -0400 Subject: [PATCH 1/2] Avoid file creation/deletion races in emsdk_env.sh by using a temporary file. Fixes https://github.com/emscripten-core/emscripten/issues/9090. --- emsdk | 10 +++++++--- emsdk_env.sh | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/emsdk b/emsdk index 0623dfa59f..01662f99fd 100755 --- a/emsdk +++ b/emsdk @@ -2531,13 +2531,17 @@ def main(): return 0 elif cmd == 'construct_env': - silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one. + if len(sys.argv) == 2: + outfile = EMSDK_SET_ENV + silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one. + else: + outfile = sys.argv [2] tools_to_activate = currently_active_tools() tools_to_activate = process_tool_list(tools_to_activate, log_errors=True) env_string = construct_env(tools_to_activate, len(sys.argv) >= 3 and 'perm' in sys.argv[2]) - open(EMSDK_SET_ENV, 'w').write(env_string) + open(outfile, 'w').write(env_string) if LINUX or OSX: - os.chmod(EMSDK_SET_ENV, 0o755) + os.chmod(outfile, 0o755) return 0 elif cmd == 'update': update_emsdk() diff --git a/emsdk_env.sh b/emsdk_env.sh index df11073891..4619f38c70 100755 --- a/emsdk_env.sh +++ b/emsdk_env.sh @@ -14,7 +14,6 @@ # ./emsdk_env.sh # # which won't have any effect. - SRC="$BASH_SOURCE" if [ "$SRC" = "" ]; then SRC="$0" @@ -23,7 +22,9 @@ CURDIR="$(pwd)" cd "$(dirname "$SRC")" unset SRC -./emsdk construct_env "$@" -. ./emsdk_set_env.sh +tmpfile=`mktemp` || exit 1 +./emsdk construct_env "$@" $tmpfile +. $tmpfile +rm -f $tmpfile cd "$CURDIR" From def06b0b60e48c3b851c8c049c1e143b03f586ab Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Fri, 26 Jul 2019 19:34:09 -0400 Subject: [PATCH 2/2] Fix indentation. --- emsdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emsdk b/emsdk index 01662f99fd..46b704bc48 100755 --- a/emsdk +++ b/emsdk @@ -2535,7 +2535,7 @@ def main(): outfile = EMSDK_SET_ENV silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one. else: - outfile = sys.argv [2] + outfile = sys.argv[2] tools_to_activate = currently_active_tools() tools_to_activate = process_tool_list(tools_to_activate, log_errors=True) env_string = construct_env(tools_to_activate, len(sys.argv) >= 3 and 'perm' in sys.argv[2])