From 6eca01f61c50c92fd54c838fd65fd053322ab341 Mon Sep 17 00:00:00 2001 From: lmchilton Date: Thu, 26 Feb 2026 12:04:56 -0500 Subject: [PATCH] pmcd: fix endianness state extraction issue On Big-Endian systems (s390x), the flags used by pmda fetch functions to signal a PMDA change were lost due to inconsistent byte-level memory manipulation Refactoring __pmdaEncodeStatus and ExtractState to treat the timestamp as a uint64_t rather than a character array allows the CPU's native endianness handling to store and retrieve flags. Adjustment to QA #1321 sleep time due to slight lag on s390x machines. --- qa/1321 | 2 +- src/libpcp_pmda/src/callback.c | 8 ++++---- src/pmcd/src/dofetch.c | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/qa/1321 b/qa/1321 index f7e6ee77118..66cf4207164 100755 --- a/qa/1321 +++ b/qa/1321 @@ -72,7 +72,7 @@ done # When new dynamic metrics are detected, the _next_ fetch will fetch them. # So wait for a bit so pmlogger has a chance to fetch the new metrics. -sleep 2 +sleep 3 # now kill pmlogger and check the new metrics appeared dynamically $sudo $PCP_BINADM_DIR/pmsignal -s TERM $pmlogger_pid >/dev/null 2>&1 diff --git a/src/libpcp_pmda/src/callback.c b/src/libpcp_pmda/src/callback.c index eedd80d4862..c75a4b52e00 100644 --- a/src/libpcp_pmda/src/callback.c +++ b/src/libpcp_pmda/src/callback.c @@ -476,18 +476,18 @@ pmdaInstance(pmInDom indom, int inst, char *name, pmInResult **result, pmdaExt * * The first byte of the (unused) timestamp field has been * co-opted as a flags byte - now indicating state changes * that have happened within a PMDA and that need to later - * be propogated through to any connected clients. + * be propagated through to any connected clients. */ static void __pmdaEncodeStatus(pmdaResult *result, unsigned char byte) { - unsigned char *flags; + uint64_t *flags; memset(&result->timestamp, 0, sizeof(result->timestamp)); if (byte) { - flags = (unsigned char *)&result->timestamp; - *flags |= byte; + flags = (uint64_t *)&result->timestamp; + *flags = byte; } } diff --git a/src/pmcd/src/dofetch.c b/src/pmcd/src/dofetch.c index 33a731b5ec0..8795f10220a 100644 --- a/src/pmcd/src/dofetch.c +++ b/src/pmcd/src/dofetch.c @@ -356,9 +356,11 @@ SendFetch(DomPmidList *dpList, AgentInfo *aPtr, ClientInfo *cPtr, int ctxnum) static int ExtractState(int i, void *timestamp) { - unsigned char byte; + uint64_t full_value; + + memcpy(&full_value, timestamp, sizeof(uint64_t)); + unsigned char byte = (unsigned char)full_value; - memcpy(&byte, timestamp, sizeof(unsigned char)); /* * integrity checks on the state change ... * - only 7 bits defined in pmapi.h (so max value is 0x3f)