diff options
author | Nathan Scott <nathans@redhat.com> | 2023-09-01 09:34:46 +1000 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2023-09-04 08:59:41 +1000 |
commit | 66c0b19ed6fec2afd4ed381665274fa83c67660e (patch) | |
tree | e8420e98aa4d5fb633cbb432babfa86d3dcdaf37 | |
parent | 9392e1d596dd2bed165c8cb522a0c9fd5fede66d (diff) |
Correct pid_t type return from Platform_getMaxPid function
Coverity scanning shows we end up passing an integer into the
Row_setPidColumnWidth routine which requires a pid_t - update
each platform to return the correct type (and never return -1
as a failure code, this was being ignored).
-rw-r--r-- | darwin/Platform.c | 2 | ||||
-rw-r--r-- | darwin/Platform.h | 2 | ||||
-rw-r--r-- | dragonflybsd/Platform.c | 2 | ||||
-rw-r--r-- | dragonflybsd/Platform.h | 2 | ||||
-rw-r--r-- | freebsd/Platform.c | 2 | ||||
-rw-r--r-- | freebsd/Platform.h | 2 | ||||
-rw-r--r-- | linux/Platform.c | 6 | ||||
-rw-r--r-- | linux/Platform.h | 2 | ||||
-rw-r--r-- | netbsd/Platform.c | 2 | ||||
-rw-r--r-- | netbsd/Platform.h | 2 | ||||
-rw-r--r-- | openbsd/Platform.c | 2 | ||||
-rw-r--r-- | openbsd/Platform.h | 2 | ||||
-rw-r--r-- | pcp/Platform.c | 4 | ||||
-rw-r--r-- | pcp/Platform.h | 2 | ||||
-rw-r--r-- | solaris/Platform.c | 2 | ||||
-rw-r--r-- | solaris/Platform.h | 2 | ||||
-rw-r--r-- | unsupported/Platform.c | 4 | ||||
-rw-r--r-- | unsupported/Platform.h | 5 |
18 files changed, 25 insertions, 22 deletions
diff --git a/darwin/Platform.c b/darwin/Platform.c index bb1ae92f..6a9c2184 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -227,7 +227,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { /* http://opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/sys/proc_internal.hh */ return 99999; } diff --git a/darwin/Platform.h b/darwin/Platform.h index cf00919f..f67db8ff 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -54,7 +54,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* mtr, unsigned int cpu); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 95f0bec6..d94d7a18 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -163,7 +163,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { int maxPid; size_t size = sizeof(maxPid); int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0); diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 91616d4f..606b004c 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -49,7 +49,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 66e1463d..9b8981ad 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -181,7 +181,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { int maxPid; size_t size = sizeof(maxPid); int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0); diff --git a/freebsd/Platform.h b/freebsd/Platform.h index cc864569..c358d85d 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -45,7 +45,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); diff --git a/linux/Platform.c b/linux/Platform.c index 33bd8ced..325f92ed 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -291,12 +291,12 @@ err: *fifteen = NAN; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { + pid_t maxPid = 4194303; FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); if (!file) - return -1; + return maxPid; - int maxPid = 4194303; int match = fscanf(file, "%32d", &maxPid); (void) match; fclose(file); diff --git a/linux/Platform.h b/linux/Platform.h index a64e54a7..763edadd 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -59,7 +59,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); diff --git a/netbsd/Platform.c b/netbsd/Platform.c index 1d6509ff..8231cdfd 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -229,7 +229,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { // https://nxr.netbsd.org/xref/src/sys/sys/ansi.h#__pid_t // pid is assigned as a 32bit Integer. return INT32_MAX; diff --git a/netbsd/Platform.h b/netbsd/Platform.h index ae34198c..a543f52d 100644 --- a/netbsd/Platform.h +++ b/netbsd/Platform.h @@ -55,7 +55,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 06594089..267da703 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -175,7 +175,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { return 2 * THREAD_PID_OFFSET; } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 790dc473..339616c1 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -47,7 +47,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); diff --git a/pcp/Platform.c b/pcp/Platform.c index 83313338..9fb3770e 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -472,13 +472,13 @@ unsigned int Platform_getMaxCPU(void) { return pcp->ncpu; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { if (pcp->pidmax) return pcp->pidmax; pmAtomValue value; if (Metric_values(PCP_PID_MAX, &value, 1, PM_TYPE_32) == NULL) - return -1; + return UINT_MAX; pcp->pidmax = value.l; return pcp->pidmax; } diff --git a/pcp/Platform.h b/pcp/Platform.h index ce21f845..f43ed54f 100644 --- a/pcp/Platform.h +++ b/pcp/Platform.h @@ -84,7 +84,7 @@ long long Platform_getBootTime(void); unsigned int Platform_getMaxCPU(void); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/solaris/Platform.c b/solaris/Platform.c index f14ae2e9..5117a448 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -175,7 +175,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = plat_loadavg[LOADAVG_15MIN]; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { int vproc = 32778; // Reasonable Solaris default kstat_ctl_t* kc = kstat_open(); diff --git a/solaris/Platform.h b/solaris/Platform.h index 00bc5832..96feeebe 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -72,7 +72,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index df7f3600..dbfddd91 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -102,8 +102,8 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = 0; } -int Platform_getMaxPid(void) { - return 1; +pid_t Platform_getMaxPid(void) { + return INT_MAX; } double Platform_setCPUValues(Meter* this, unsigned int cpu) { diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 8e08dc23..c4cd06a0 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -8,6 +8,9 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include <stdbool.h> +#include <sys/types.h> + #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" @@ -40,7 +43,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); |