Skip to content

Commit

Permalink
Correct pid_t type return from Platform_getMaxPid function
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
natoscott committed Aug 31, 2023
1 parent 9392e1d commit b0b6ff7
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion darwin/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion dragonflybsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dragonflybsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion freebsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion freebsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 4 additions & 5 deletions linux/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,13 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
*fifteen = NAN;
}

int Platform_getMaxPid(void) {
pid_t Platform_getMaxPid(void) {
int 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;
(void)fscanf(file, "%32d", &maxPid);
fclose(file);
return maxPid;
}
Expand Down
2 changes: 1 addition & 1 deletion linux/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion netbsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion netbsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion openbsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion openbsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions pcp/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion pcp/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion solaris/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion solaris/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion unsupported/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
}

int Platform_getMaxPid(void) {
return 1;
return INT_MAX;
}

double Platform_setCPUValues(Meter* this, unsigned int cpu) {
Expand Down
5 changes: 4 additions & 1 deletion unsupported/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b0b6ff7

Please sign in to comment.