From 2d27ea22542fd36bf182f78bbd9e6999347de475 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 31 Jan 2025 16:53:25 +1100 Subject: [PATCH] libpcp: fix endian issue in big-endian __pmTimestamp writing Resolves: RHEL-69722 --- big-endian-timestamps.patch | 93 +++++++++++++++++++++++++++++++++++++ pcp.spec | 6 ++- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 big-endian-timestamps.patch diff --git a/big-endian-timestamps.patch b/big-endian-timestamps.patch new file mode 100644 index 0000000..854afe1 --- /dev/null +++ b/big-endian-timestamps.patch @@ -0,0 +1,93 @@ +commit 4df35d2b5070f289bf3856f035551cde8ca22e06 +Author: Nathan Scott +Date: Thu Jan 30 12:11:26 2025 +1100 + + libpcp: fix endian issue in big-endian __pmTimestamp writing + + Mirror an earlier endian fix in the reading code for big-endian + platforms for writing __pmTimestamp structures. Affects v3 log + writing only, and big endian platforms only. + + Some minor code cleanup also; fix an unused-function warning on + big endian build machines and keep the various timestamp get/put + routines together in logmeta.c for easier cross-referencing. + + Resolves Red Hat bug RHEL-69722 + Resolves github issue #2110 + +diff --git a/src/libpcp/src/endian.c b/src/libpcp/src/endian.c +index fc6d931f99..f700fc9c56 100644 +--- a/src/libpcp/src/endian.c ++++ b/src/libpcp/src/endian.c +@@ -77,6 +77,7 @@ __ntohpmLabel(pmLabel * const label) + } + #endif + ++#ifndef __htonpmValueBlock + static void + __htonpmTimespec(pmTimespec * const tsp) + { +@@ -84,7 +85,6 @@ __htonpmTimespec(pmTimespec * const tsp) + __htonll((char *)&tsp->tv_nsec); + } + +-#ifndef __htonpmValueBlock + static void + htonEventArray(pmValueBlock * const vb, int highres) + { +diff --git a/src/libpcp/src/logmeta.c b/src/libpcp/src/logmeta.c +index 9db81af860..e04545d425 100644 +--- a/src/libpcp/src/logmeta.c ++++ b/src/libpcp/src/logmeta.c +@@ -1823,17 +1823,6 @@ __pmLoadTimestamp(const __int32_t *buf, __pmTimestamp *tsp) + } + } + +-void +-__pmLoadTimeval(const __int32_t *buf, __pmTimestamp *tsp) +-{ +- tsp->sec = (__int32_t)ntohl(buf[0]); +- tsp->nsec = ntohl(buf[1]) * 1000; +- if (pmDebugOptions.logmeta && pmDebugOptions.desperate) { +- fprintf(stderr, "__pmLoadTimeval: network(%08x %08x usec)", buf[0], buf[1]); +- fprintf(stderr, " -> %" FMT_INT64 ".%09d (%llx %x nsec)\n", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec); +- } +-} +- + void + __pmPutTimestamp(const __pmTimestamp *tsp, __int32_t *buf) + { +@@ -1845,8 +1834,13 @@ __pmPutTimestamp(const __pmTimestamp *tsp, __int32_t *buf) + * need to dodge endian issues here ... want the MSB 32-bits of sec + * in buf[0] and the LSB 32 bits of sec in buf[1] + */ +- buf[0] = (stamp.sec >> 32) & 0xffffffff; +- buf[1] = stamp.sec & 0xffffffff; ++#if __BYTE_ORDER == __LITTLE_ENDIAN ++ buf[0] = (__int32_t)((__int64_t)(stamp.sec >> 32)); ++ buf[1] = (__int32_t)((__int64_t)(stamp.sec & 0x00000000ffffffffLL)); ++#else ++ buf[1] = (__int32_t)((__int64_t)(stamp.sec >> 32)); ++ buf[0] = (__int32_t)((__int64_t)(stamp.sec & 0x00000000ffffffffLL)); ++#endif + buf[2] = stamp.nsec; + if (pmDebugOptions.logmeta && pmDebugOptions.desperate) { + fprintf(stderr, "__pmPutTimestamp: %" FMT_INT64 ".%09d (%llx %x nsec)", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec); +@@ -1854,6 +1848,17 @@ __pmPutTimestamp(const __pmTimestamp *tsp, __int32_t *buf) + } + } + ++void ++__pmLoadTimeval(const __int32_t *buf, __pmTimestamp *tsp) ++{ ++ tsp->sec = (__int32_t)ntohl(buf[0]); ++ tsp->nsec = ntohl(buf[1]) * 1000; ++ if (pmDebugOptions.logmeta && pmDebugOptions.desperate) { ++ fprintf(stderr, "__pmLoadTimeval: network(%08x %08x usec)", buf[0], buf[1]); ++ fprintf(stderr, " -> %" FMT_INT64 ".%09d (%llx %x nsec)\n", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec); ++ } ++} ++ + void + __pmPutTimeval(const __pmTimestamp *tsp, __int32_t *buf) + { diff --git a/pcp.spec b/pcp.spec index a9eef48..352b9c8 100644 --- a/pcp.spec +++ b/pcp.spec @@ -1,6 +1,6 @@ Name: pcp Version: 6.3.2 -Release: 4%{?dist} +Release: 5%{?dist} Summary: System-level performance monitoring and performance management License: GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0 URL: https://pcp.io @@ -9,6 +9,7 @@ Source0: https://github.com/performancecopilot/pcp/releases/pcp-%{version}.src.t Patch0: pcp-xsos-fixes.patch Patch1: selinux-pmie-and-pmlogger.patch +Patch2: big-endian-timestamps.patch %if 0%{?fedora} >= 40 || 0%{?rhel} >= 10 ExcludeArch: %{ix86} @@ -3601,6 +3602,9 @@ fi %files zeroconf -f pcp-zeroconf-files.rpm %changelog +* Fri Jan 31 2025 Nathan Scott - 6.3.2-5 +- Fix writing of v3 archive timestamps on s390x (RHEL-69722) + * Thu Jan 23 2025 Zdenek Pytela - 6.3.2-4 - Rebuild with selinux-policy-40.13.23-1