File pacemaker#3286-0001-Low-libcrmcommon-Check-correct-env-vars-in-pcmk__nod.patch of Package pacemaker.38493

From ff6109075c4c73f718d74fc449e8973917da0d20 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Sat, 9 Dec 2023 12:09:57 -0800
Subject: [PATCH] Low: libcrmcommon: Check correct env vars in
 pcmk__node_attr_target()

All CRM_meta environment variables begin with OCF_RESKEY_. Here we add
the prefix.

Previously, we were checking variables that never existed.

It's likely that pcmk__node_attr_target() has never worked correctly
with container-attribute-target=host. Resource agents have worked around
this by calling ocf_attribute_target() from the resource-agents repo.

Note that this fix only applies to container images built using a
version of Pacemaker that includes the fix. Resource agents should
continue using ocf_attribute_target() for a while, in case they're run
by an older container. (The resource agents inside the Pacemaker source
tree are obviously exempt.)

Ref T733

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
 lib/common/attrs.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/common/attrs.c b/lib/common/attrs.c
index 2be03b424..76e3f0de0 100644
--- a/lib/common/attrs.c
+++ b/lib/common/attrs.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2022 the Pacemaker project contributors
+ * Copyright 2011-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -18,7 +18,8 @@
 #include <crm/msg_xml.h>
 #include <crm/common/attrd_internal.h>
 
-#define LRM_TARGET_ENV "OCF_RESKEY_" CRM_META "_" XML_LRM_ATTR_TARGET
+#define OCF_RESKEY_PREFIX "OCF_RESKEY_"
+#define LRM_TARGET_ENV OCF_RESKEY_PREFIX CRM_META "_" XML_LRM_ATTR_TARGET
 
 /*!
  * \internal
@@ -39,10 +40,18 @@ const char *
 pcmk__node_attr_target(const char *name)
 {
     if (name == NULL || pcmk__strcase_any_of(name, "auto", "localhost", NULL)) {
+        char buf[128] = OCF_RESKEY_PREFIX;
+        size_t offset = sizeof(OCF_RESKEY_PREFIX) - 1;
         char *target_var = crm_meta_name(XML_RSC_ATTR_TARGET);
         char *phys_var = crm_meta_name(PCMK__ENV_PHYSICAL_HOST);
-        const char *target = getenv(target_var);
-        const char *host_physical = getenv(phys_var);
+        const char *target = NULL;
+        const char *host_physical = NULL;
+
+        snprintf(buf + offset, sizeof(buf) - offset, "%s", target_var);
+        target = getenv(buf);
+
+        snprintf(buf + offset, sizeof(buf) - offset, "%s", phys_var);
+        host_physical = getenv(buf);
 
         // It is important to use the name by which the scheduler knows us
         if (host_physical && pcmk__str_eq(target, "host", pcmk__str_casei)) {
-- 
2.35.3

openSUSE Build Service is sponsored by