From 4ffb4541452a95ae964c562c89e31c49e39dbaa7 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 30 Jun 2015 11:00:32 +1000 Subject: [PATCH] Add header guard to functions/functions-common To avoid sourcing this twice and getting globals mixed up, particularly when using multiple plugins, add a "header guard" that ensures we only source it once. In general I don't think functions/functions-common have been written or considered to be idempotent. I don't think going down that path is going to be a long-term solution as it's easy to break. Change-Id: Idca49eb996d2b7ff3779ec27ed672a2da7852590 Closes-Bug: #1469178 --- functions | 4 ++++ functions-common | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/functions b/functions index 1668e16b6d..e4aea677d6 100644 --- a/functions +++ b/functions @@ -10,6 +10,10 @@ # - ``GLANCE_HOSTPORT`` # +# ensure we don't re-source this in the same environment +[[ -z "$_DEVSTACK_FUNCTIONS" ]] || return 0 +declare -r _DEVSTACK_FUNCTIONS=1 + # Include the common functions FUNC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd) source ${FUNC_DIR}/functions-common diff --git a/functions-common b/functions-common index 061a9356f5..5f22bf0c6d 100644 --- a/functions-common +++ b/functions-common @@ -36,6 +36,10 @@ XTRACE=$(set +o | grep xtrace) set +o xtrace +# ensure we don't re-source this in the same environment +[[ -z "$_DEVSTACK_FUNCTIONS_COMMON" ]] || return 0 +declare -r _DEVSTACK_FUNCTIONS_COMMON=1 + # Global Config Variables declare -A GITREPO declare -A GITBRANCH