summary refs log tree commit diff
path: root/src/nm-cloud-setup/nmcs-provider-ec2.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
committerMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
commit05e4a733f2141995181a551854d5df929f084adf (patch)
tree83bb937740a6667525ba0df046748ecaa829c269 /src/nm-cloud-setup/nmcs-provider-ec2.c
parent14b0f3a9dc9ea90d60a3b057350fd4d637dc021a (diff)
New upstream version 1.44.0 upstream/1.44.0
Diffstat (limited to 'src/nm-cloud-setup/nmcs-provider-ec2.c')
-rw-r--r--src/nm-cloud-setup/nmcs-provider-ec2.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c
index 65a8f629..9cdc7a0c 100644
--- a/src/nm-cloud-setup/nmcs-provider-ec2.c
+++ b/src/nm-cloud-setup/nmcs-provider-ec2.c
@@ -21,27 +21,7 @@
 #define NM_EC2_TOKEN_TTL_HEADER "X-aws-ec2-metadata-token-ttl-seconds: 180"
 #define NM_EC2_TOKEN_HEADER     "X-aws-ec2-metadata-token: "
 
-static const char *
-_ec2_base(void)
-{
-    static const char *base_cached = NULL;
-    const char        *base;
-
-again:
-    base = g_atomic_pointer_get(&base_cached);
-    if (G_UNLIKELY(!base)) {
-        /* The base URI can be set via environment variable.
-         * This is mainly for testing, it's not usually supposed to be configured.
-         * Consider this private API! */
-        base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2_HOST"));
-        base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_EC2_BASE);
-
-        if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
-            goto again;
-    }
-
-    return base;
-}
+NMCS_DEFINE_HOST_BASE(_ec2_base, NMCS_ENV_NM_CLOUD_SETUP_EC2_HOST, NM_EC2_BASE);
 
 #define _ec2_uri_concat(...) nmcs_utils_uri_build_concat(_ec2_base(), __VA_ARGS__)
 #define _ec2_uri_interfaces(...) \
@@ -435,7 +415,7 @@ nmcs_provider_ec2_class_init(NMCSProviderEC2Class *klass)
     object_class->dispose = dispose;
 
     provider_class->_name                 = "ec2";
-    provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2");
+    provider_class->_env_provider_enabled = NMCS_ENV_NM_CLOUD_SETUP_EC2;
     provider_class->detect                = detect;
     provider_class->get_config            = get_config;
 }