Get FreeBSD tree to compile again with latest changes.

This commit is contained in:
Hisham Muhammad 2015-03-16 03:13:42 -03:00
parent 40f3391a3c
commit adbfe3c3f1
16 changed files with 333 additions and 26 deletions

View File

@ -129,8 +129,10 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
ProcessField* fields = this->settings->fields;
for (; *fields; fields++) {
if (Process_fields[*fields].name) {
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
}
}
return this;
}

45
MainPanel.h Normal file
View File

@ -0,0 +1,45 @@
/* Do not edit this file. It was automatically generated. */
#ifndef HEADER_MainPanel
#define HEADER_MainPanel
/*
htop - ColumnsPanel.h
(C) 2004-2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Panel.h"
#include "Action.h"
#include "Settings.h"
typedef struct MainPanel_ {
Panel super;
State* state;
FunctionBar* fuBar;
Htop_Action *keys;
pid_t pidSearch;
} MainPanel;
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
void MainPanel_updateTreeFunctions(FunctionBar* fuBar, bool mode);
void MainPanel_pidSearch(MainPanel* this, int ch);
int MainPanel_selectedPid(MainPanel* this);
const char* MainPanel_getValue(MainPanel* this, int i);
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
extern PanelClass MainPanel_class;
MainPanel* MainPanel_new(FunctionBar* fuBar);
void MainPanel_setState(MainPanel* this, State* state);
void MainPanel_delete(Object* object);
#endif

View File

@ -12,7 +12,7 @@ applications_DATA = htop.desktop
pixmapdir = $(datadir)/pixmaps
pixmap_DATA = htop.png
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)"
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)"
AM_CPPFLAGS = -DNDEBUG
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
@ -34,6 +34,7 @@ UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h AffinityPanel.h \
HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h
if HTOP_LINUX
htop_CFLAGS += -rdynamic
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c
@ -43,10 +44,10 @@ endif
if HTOP_FREEBSD
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
freebsd/FreeBSDCRT.c
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
freebsd/FreeBSDCRT.h
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
endif
if HTOP_UNSUPPORTED

View File

@ -49,6 +49,16 @@ typedef struct ProcessList_ {
bool topologyOk;
#endif
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
int cpuCount;
} ProcessList;

View File

@ -43,6 +43,16 @@ typedef struct ProcessList_ {
bool topologyOk;
#endif
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
int cpuCount;
} ProcessList;

View File

@ -139,7 +139,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) {
// This "+1" is for compatibility with the older enum format.
int id = atoi(ids[i]) + 1;
if (id > 0 && id < Platform_numberOfFields) {
if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) {
fields[j] = id;
*flags |= Process_fields[id].flags;
j++;

15
freebsd/Battery.c Normal file
View File

@ -0,0 +1,15 @@
/*
htop - freebsd/Battery.c
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "BatteryMeter.h"
void Battery_getData(double* level, ACPresence* isOnAC) {
// TODO
*level = -1;
*isOnAC = AC_ERROR;
}

15
freebsd/Battery.h Normal file
View File

@ -0,0 +1,15 @@
/* Do not edit this file. It was automatically generated. */
#ifndef HEADER_Battery
#define HEADER_Battery
/*
htop - freebsd/Battery.h
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
void Battery_getData(double* level, ACPresence* isOnAC);
#endif

134
freebsd/FreeBSDProcess.c Normal file
View File

@ -0,0 +1,134 @@
/*
htop - FreeBSDProcess.c
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Process.h"
#include "ProcessList.h"
#include "FreeBSDProcess.h"
#include "Platform.h"
#include "CRT.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
/*{
typedef enum FreeBSDProcessFields {
// Add platform-specific fields here, with ids >= 100
LAST_PROCESSFIELD = 100,
} FreeBSDProcessField;
typedef struct FreeBSDProcess_ {
Process super;
} FreeBSDProcess;
}*/
ProcessFieldData Process_fields[] = {
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
[SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
char* Process_pidFormat = "%7u ";
char* Process_tpgidFormat = "%7u ";
void Process_setupColumnWidths() {
int maxPid = Platform_getMaxPid();
if (maxPid == -1) return;
if (maxPid > 99999) {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
Process_fields[TPGID].title = " TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
Process_pidFormat = "%7u ";
Process_tpgidFormat = "%7d ";
} else {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
Process_fields[TPGID].title = "TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
Process_pidFormat = "%5u ";
Process_tpgidFormat = "%5d ";
}
}
FreeBSDProcess* FreeBSDProcess_new(Settings* settings) {
FreeBSDProcess* this = calloc(sizeof(FreeBSDProcess), 1);
Object_setClass(this, Class(Process));
Process_init(&this->super, settings);
return this;
}
void Process_delete(Object* cast) {
FreeBSDProcess* this = (FreeBSDProcess*) cast;
Process_done((Process*)cast);
free(this);
}
void Process_writeField(Process* this, RichString* str, ProcessField field) {
//FreeBSDProcess* fp = (FreeBSDProcess*) this;
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
//int n = sizeof(buffer) - 1;
switch (field) {
// add FreeBSD-specific fields here
default:
Process_writeDefaultField(this, str, field);
return;
}
RichString_append(str, attr, buffer);
}
long Process_compare(const void* v1, const void* v2) {
FreeBSDProcess *p1, *p2;
Settings *settings = ((Process*)v1)->settings;
if (settings->direction == 1) {
p1 = (FreeBSDProcess*)v1;
p2 = (FreeBSDProcess*)v2;
} else {
p2 = (FreeBSDProcess*)v1;
p1 = (FreeBSDProcess*)v2;
}
switch (settings->sortKey) {
// add FreeBSD-specific fields here
default:
return Process_defaultCompare(v1, v2);
}
}
bool Process_isThread(Process* this) {
(void) this;
// TODO
return false;
}

40
freebsd/FreeBSDProcess.h Normal file
View File

@ -0,0 +1,40 @@
/* Do not edit this file. It was automatically generated. */
#ifndef HEADER_FreeBSDProcess
#define HEADER_FreeBSDProcess
/*
htop - FreeBSDProcess.h
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
typedef enum FreeBSDProcessFields {
// Add platform-specific fields here, with ids >= 100
LAST_PROCESSFIELD = 100,
} FreeBSDProcessField;
typedef struct FreeBSDProcess_ {
Process super;
} FreeBSDProcess;
extern ProcessFieldData Process_fields[];
extern char* Process_pidFormat;
extern char* Process_tpgidFormat;
void Process_setupColumnWidths();
FreeBSDProcess* FreeBSDProcess_new(Settings* settings);
void Process_delete(Object* cast);
void Process_writeField(Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
bool Process_isThread(Process* this);
#endif

View File

@ -18,9 +18,17 @@ in the source distribution for its full text.
#include <kvm.h>
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int totalPeriod;
} CPUData;
typedef struct FreeBSDProcessList_ {
ProcessList super;
kvm_t* kd;
CPUData* cpus;
} FreeBSDProcessList;
}*/
@ -31,21 +39,21 @@ static int MIB_hw_physmem[2];
static int pageSizeKb;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
FreeBSDProcessList* fpl = calloc(1, sizeof(FreeBSDProcessList));
ProcessList* pl = (ProcessList*) fpl;
ProcessList_init(pl, usersTable, pidWhiteList);
ProcessList_init(pl, usersTable, pidWhiteList, userId);
int cpus = 1;
size_t sizeof_cpus = sizeof(cpus);
int err = sysctlbyname("hw.ncpu", &cpus, &sizeof_cpus, NULL, 0);
if (err) cpus = 1;
pl->cpuCount = MAX(cpus, 1);
pl->cpus = realloc(pl->cpus, cpus * sizeof(CPUData));
fpl->cpus = realloc(fpl->cpus, cpus * sizeof(CPUData));
for (int i = 0; i < cpus; i++) {
pl->cpus[i].totalTime = 1;
pl->cpus[i].totalPeriod = 1;
fpl->cpus[i].totalTime = 1;
fpl->cpus[i].totalPeriod = 1;
}
size_t len;

View File

@ -12,13 +12,21 @@ in the source distribution for its full text.
#include <kvm.h>
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int totalPeriod;
} CPUData;
typedef struct FreeBSDProcessList_ {
ProcessList super;
kvm_t* kd;
CPUData* cpus;
} FreeBSDProcessList;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList);
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* this);

View File

@ -15,6 +15,7 @@ in the source distribution for its full text.
#include "UptimeMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "FreeBSDProcess.h"
#include <sys/types.h>
#include <sys/sysctl.h>
@ -26,8 +27,15 @@ in the source distribution for its full text.
/*{
#include "Action.h"
#include "BatteryMeter.h"
extern ProcessFieldData Process_fields[];
}*/
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
int Platform_numberOfFields = LAST_PROCESSFIELD;
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
@ -94,9 +102,18 @@ int Platform_getMaxPid() {
return maxPid;
}
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) {
double Platform_setCPUValues(Meter* this, int cpu) {
// TODO
*level = -1;
*isOnAC = AC_ERROR;
}
void Platform_setMemoryValues(Meter* this) {
// TODO
}
void Platform_setSwapValues(Meter* this) {
// TODO
}
void Platform_setTasksValues(Meter* this) {
// TODO
}

View File

@ -12,6 +12,13 @@ in the source distribution for its full text.
#include "Action.h"
#include "BatteryMeter.h"
extern ProcessFieldData Process_fields[];
extern ProcessField Platform_defaultFields[];
extern int Platform_numberOfFields;
void Platform_setBindings(Htop_Action* keys);
extern MeterClass* Platform_meterTypes[];
@ -22,7 +29,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid();
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC);
double Platform_setCPUValues(Meter* this, int cpu);
void Platform_setMemoryValues(Meter* this);
void Platform_setSwapValues(Meter* this);
void Platform_setTasksValues(Meter* this);
#endif

View File

@ -83,7 +83,7 @@ typedef enum LinuxProcessFields {
OOM = 114,
#endif
IO_PRIORITY = 115,
LAST_PROCESSFIELD
LAST_PROCESSFIELD = 116,
} LinuxProcessField;
#include "IOPriority.h"

View File

@ -69,16 +69,6 @@ typedef struct LinuxProcessList_ {
CPUData* cpus;
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
} LinuxProcessList;
#ifndef PROCDIR