diff options
author | Benny Baumann <BenBE@geshi.org> | 2024-03-10 17:08:04 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-03-27 20:06:42 +0100 |
commit | 78c6aacfb50e602ea59db51fc19fe7c4cf370d7c (patch) | |
tree | bf9091a85cb9c2d5c2b4591ff3c9552754e4492e | |
parent | 49f0ca2d70908140566af667492e63e7ad546321 (diff) |
Avoid glibc FILE API for maxpid
-rw-r--r-- | linux/Platform.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/linux/Platform.c b/linux/Platform.c index ca289e6c..a47918fe 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -300,15 +300,21 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } pid_t Platform_getMaxPid(void) { - pid_t maxPid = 4194303; - FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); - if (!file) - return maxPid; - - int match = fscanf(file, "%32d", &maxPid); - (void) match; - fclose(file); - return maxPid; + char piddata[32] = {0}; + + ssize_t pidread = xReadfile(PROCDIR "/sys/kernel/pid_max", piddata, sizeof(piddata)); + if (pidread < 1) + goto err; + + int pidmax = 0; + int match = sscanf(piddata, "%32d", &pidmax); + if (match != 1) + goto err; + + return pidmax; + +err: + return 0x3FFFFF; // 4194303 } double Platform_setCPUValues(Meter* this, unsigned int cpu) { |