pcp/big-endian-timestamps.patch
2025-01-31 16:53:25 +11:00

94 lines
3.3 KiB
Diff

commit 4df35d2b5070f289bf3856f035551cde8ca22e06
Author: Nathan Scott <nathans@redhat.com>
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)
{