diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-11-27 20:10:23 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-11-27 20:10:23 -0200 |
commit | b4f6b110925a56d0818034ad1ecce8214ac873a0 (patch) | |
tree | cfd0de9013de6f50ce6bcab14592e44442f853e4 | |
parent | 5578a316f047551d21f04a5df47fd705bf486ee3 (diff) |
Move "get max pid" code into platform specific area.
-rw-r--r-- | Process.c | 10 | ||||
-rw-r--r-- | Process.h | 2 | ||||
-rw-r--r-- | htop.c | 2 | ||||
-rw-r--r-- | linux/Platform.c | 9 | ||||
-rw-r--r-- | unsupported/Platform.c | 4 |
5 files changed, 19 insertions, 8 deletions
@@ -11,6 +11,7 @@ in the source distribution for its full text. #include "CRT.h" #include "String.h" #include "RichString.h" +#include "Platform.h" #include <stdio.h> #include <sys/time.h> @@ -284,12 +285,9 @@ static int Process_getuid = -1; static char* Process_pidFormat = "%7u "; static char* Process_tpgidFormat = "%7u "; -void Process_getMaxPid() { - FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); - if (!file) return; - int maxPid = 4194303; - fscanf(file, "%32d", &maxPid); - fclose(file); +void Process_setupColumnWidths() { + int maxPid = Platform_getMaxPid(); + if (maxPid == -1) return; if (maxPid > 99999) { Process_fieldTitles[PID] = " PID "; Process_fieldTitles[PPID] = " PPID "; @@ -179,7 +179,7 @@ extern const int Process_fieldFlags[]; extern const char *Process_fieldTitles[]; -void Process_getMaxPid(); +void Process_setupColumnWidths(); #define ONE_K 1024L #define ONE_M (ONE_K * ONE_K) @@ -680,7 +680,7 @@ int main(int argc, char** argv) { ProcessList* pl = ProcessList_new(ut, pidWhiteList); pl->userOnly = userOnly; pl->userId = userId; - Process_getMaxPid(); + Process_setupColumnWidths(); Header* header = Header_new(pl); Settings* settings = Settings_new(pl, header, pl->cpuCount); diff --git a/linux/Platform.c b/linux/Platform.c index ebd10331..4607ad68 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -93,3 +93,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } } +int Platform_getMaxPid() { + FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); + if (!file) return -1; + int maxPid = 4194303; + fscanf(file, "%32d", &maxPid); + fclose(file); + return maxPid; +} + diff --git a/unsupported/Platform.c b/unsupported/Platform.c index b13b495b..764f890e 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -54,3 +54,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *five = 0; *fifteen = 0; } + +int Platform_getMaxPid() { + return -1; +} |