Merge branch 'master' into freebsd

This commit is contained in:
Hisham Muhammad 2014-11-27 20:10:53 -02:00
commit da0956d1cd
5 changed files with 21 additions and 9 deletions

View File

@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "CRT.h" #include "CRT.h"
#include "String.h" #include "String.h"
#include "RichString.h" #include "RichString.h"
#include "Platform.h"
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <sys/time.h>
@ -284,12 +285,9 @@ static int Process_getuid = -1;
static char* Process_pidFormat = "%7u "; static char* Process_pidFormat = "%7u ";
static char* Process_tpgidFormat = "%7u "; static char* Process_tpgidFormat = "%7u ";
void Process_getMaxPid() { void Process_setupColumnWidths() {
FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); int maxPid = Platform_getMaxPid();
if (!file) return; if (maxPid == -1) return;
int maxPid = 4194303;
fscanf(file, "%32d", &maxPid);
fclose(file);
if (maxPid > 99999) { if (maxPid > 99999) {
Process_fieldTitles[PID] = " PID "; Process_fieldTitles[PID] = " PID ";
Process_fieldTitles[PPID] = " PPID "; Process_fieldTitles[PPID] = " PPID ";

View File

@ -179,7 +179,7 @@ extern const int Process_fieldFlags[];
extern const char *Process_fieldTitles[]; extern const char *Process_fieldTitles[];
void Process_getMaxPid(); void Process_setupColumnWidths();
#define ONE_K 1024L #define ONE_K 1024L
#define ONE_M (ONE_K * ONE_K) #define ONE_M (ONE_K * ONE_K)

5
htop.c
View File

@ -656,11 +656,12 @@ int main(int argc, char** argv) {
} }
} }
#ifdef HAVE_PROC
if (access(PROCDIR, R_OK) != 0) { if (access(PROCDIR, R_OK) != 0) {
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR); fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
exit(1); exit(1);
} }
#endif
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
char *locale = setlocale(LC_ALL, NULL); char *locale = setlocale(LC_ALL, NULL);
@ -680,7 +681,7 @@ int main(int argc, char** argv) {
ProcessList* pl = ProcessList_new(ut, pidWhiteList); ProcessList* pl = ProcessList_new(ut, pidWhiteList);
pl->userOnly = userOnly; pl->userOnly = userOnly;
pl->userId = userId; pl->userId = userId;
Process_getMaxPid(); Process_setupColumnWidths();
Header* header = Header_new(pl); Header* header = Header_new(pl);
Settings* settings = Settings_new(pl, header, pl->cpuCount); Settings* settings = Settings_new(pl, header, pl->cpuCount);

View File

@ -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;
}

View File

@ -54,3 +54,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
*five = 0; *five = 0;
*fifteen = 0; *fifteen = 0;
} }
int Platform_getMaxPid() {
return -1;
}