summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-11-27 20:10:23 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-11-27 20:10:23 -0200
commitb4f6b110925a56d0818034ad1ecce8214ac873a0 (patch)
treecfd0de9013de6f50ce6bcab14592e44442f853e4
parent5578a316f047551d21f04a5df47fd705bf486ee3 (diff)
Move "get max pid" code into platform specific area.
-rw-r--r--Process.c10
-rw-r--r--Process.h2
-rw-r--r--htop.c2
-rw-r--r--linux/Platform.c9
-rw-r--r--unsupported/Platform.c4
5 files changed, 19 insertions, 8 deletions
diff --git a/Process.c b/Process.c
index 7fc36a1a..de25cbbb 100644
--- a/Process.c
+++ b/Process.c
@@ -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 ";
diff --git a/Process.h b/Process.h
index c4ef808d..6bd40686 100644
--- a/Process.h
+++ b/Process.h
@@ -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)
diff --git a/htop.c b/htop.c
index e70c270d..66088e7a 100644
--- a/htop.c
+++ b/htop.c
@@ -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;
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy