From ca7a07319412e695f13045ae8dfbe238ff3c405c Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 19 Sep 2024 04:27:07 +1000 Subject: [PATCH 1/2] build: ensure pmie config.default created with correct ownership When the pcp-zeroconf package install creates config.default for pmie (rather than updating it) ensure correct pcp:pcp ownership. Resolves Red Hat issue RHEL-59366 --- build/rpm/pcp.spec.in | 9 +++++---- build/rpm/redhat.spec | 9 +++++---- debian/pcp-zeroconf.postinst | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/build/rpm/pcp.spec.in b/build/rpm/pcp.spec.in index c5f6d0a020..8ae4018104 100755 --- a/build/rpm/pcp.spec.in +++ b/build/rpm/pcp.spec.in @@ -220,11 +220,12 @@ fi } %global run_pmieconf() %{expand: -if [ -w "%1" ] +if [ -d "%1" -a -w "%1" -a -w "%1/%2" ] then - pmieconf -c enable "%2" + pmieconf -f "%1/%2" -c enable "%3" + chown pcp:pcp "%1/%2" 2>/dev/null else - echo "WARNING: Cannot write to %1, skipping pmieconf enable of %2." >&2 + echo "WARNING: Cannot write to %1/%2, skipping pmieconf enable of %3." >&2 fi } @@ -2747,7 +2748,7 @@ for PMDA in $needinstall ; do fi done # auto-enable these usually optional pmie rules -%{run_pmieconf "$PCP_PMIECONFIG_DIR" dmthin} +%{run_pmieconf "$PCP_PMIECONFIG_DIR" config.default dmthin} %if "@enable_systemd@" == "true" systemctl restart pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1 systemctl enable pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1 diff --git a/build/rpm/redhat.spec b/build/rpm/redhat.spec index b669729b00..da1bd20cee 100644 --- a/build/rpm/redhat.spec +++ b/build/rpm/redhat.spec @@ -476,11 +476,12 @@ fi } %global run_pmieconf() %{expand: -if [ -w "%1" ] +if [ -d "%1" -a -w "%1" -a -w "%1/%2" ] then - pmieconf -c enable "%2" + pmieconf -f "%1/%2" -c enable "%3" + chown pcp:pcp "%1/%2" 2>/dev/null else - echo "WARNING: Cannot write to %1, skipping pmieconf enable of %2." >&2 + echo "WARNING: Cannot write to %1/%2, skipping pmieconf enable of %3." >&2 fi } @@ -3223,7 +3224,7 @@ for PMDA in dm nfsclient openmetrics ; do fi done # auto-enable these usually optional pmie rules -%{run_pmieconf "$PCP_PMIECONFIG_DIR" dmthin} +%{run_pmieconf "$PCP_PMIECONFIG_DIR" config.default dmthin} %if 0%{?rhel} <= 9 %if !%{disable_systemd} systemctl restart pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1 diff --git a/debian/pcp-zeroconf.postinst b/debian/pcp-zeroconf.postinst index 4837c7030d..26eabdcc7e 100644 --- a/debian/pcp-zeroconf.postinst +++ b/debian/pcp-zeroconf.postinst @@ -12,4 +12,5 @@ for PMDA in dm nfsclient openmetrics ; do done # auto-enable these usually optional pmie rules -pmieconf -c enable dmthin +pmieconf -f /var/lib/pcp/config/pmie/config.default -c enable dmthin +chown pcp:pcp /var/lib/pcp/config/pmie/config.default From 7423036e42c9013bff43f0889f877ea543fb2bf5 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 19 Sep 2024 04:34:30 +1000 Subject: [PATCH 2/2] pmdalinux: ensure divide-by-zero cannot happen with tmpfs.full Nikhil Jain reported and diagnosed a NaN value from tmpfs.full on his system, this commit adds protection for several places where a division-by-zero could occur in the Linux PMDA. --- src/pmdas/linux/pmda.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pmdas/linux/pmda.c b/src/pmdas/linux/pmda.c index ad4fe5995f..39a0850c10 100644 --- a/src/pmdas/linux/pmda.c +++ b/src/pmdas/linux/pmda.c @@ -8877,8 +8877,10 @@ linux_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) break; case 8: /* filesys.full */ used = (__uint64_t)(sbuf->f_blocks - sbuf->f_bfree); - ull = used + (__uint64_t)sbuf->f_bavail; - atom->d = (100.0 * (double)used) / (double)ull; + if ((ull = used + (__uint64_t)sbuf->f_bavail) == 0) + atom->d = 0; /* protect against divide-by-zero */ + else + atom->d = (100.0 * (double)used) / (double)ull; break; case 9: /* filesys.blocksize -- added by Mike Mason */ atom->ul = sbuf->f_bsize; @@ -8949,8 +8951,10 @@ linux_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) break; case 7: /* tmpfs.full */ used = (__uint64_t)(sbuf->f_blocks - sbuf->f_bfree); - ull = used + (__uint64_t)sbuf->f_bavail; - atom->d = (100.0 * (double)used) / (double)ull; + if ((ull = used + (__uint64_t)sbuf->f_bavail) == 0) + atom->d = 0; /* protect against divide-by-zero */ + else + atom->d = (100.0 * (double)used) / (double)ull; break; default: return PM_ERR_PMID; @@ -10659,6 +10663,8 @@ linux_init(pmdaInterface *dp) hz = atoi(envpath); } else hz = sysconf(_SC_CLK_TCK); + if (hz == 0) /* protect against divide-by-zero */ + hz = 1; if ((envpath = getenv("LINUX_NCPUS")) != NULL) { /* * If $LINUX_NCPUS is set, this is a QA setting that