Merge branch 'cleanup-init-done' into master

This commit is contained in:
Nathan Scott 2020-11-23 17:34:44 +11:00
commit 003f2c06a4
15 changed files with 159 additions and 87 deletions

View File

@ -131,11 +131,20 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
int Platform_numberOfFields = 100;
void Platform_init(void) {
/* no platform-specific setup needed */
}
int Platform_numberOfFields = 100;
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
int Platform_getUptime() {
struct timeval bootTime, currTime;

View File

@ -19,20 +19,23 @@ in the source distribution for its full text.
#include "ProcessLocksScreen.h"
#include "SignalsPanel.h"
extern ProcessFieldData Process_fields[];
extern ProcessField Platform_defaultFields[];
extern int Platform_numberOfFields;
extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;
extern ProcessFieldData Process_fields[];
extern const MeterClass* const Platform_meterTypes[];
void Platform_setBindings(Htop_Action* keys);
void Platform_init(void);
extern int Platform_numberOfFields;
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);

View File

@ -74,10 +74,6 @@ const SignalItem Platform_signals[] = {
const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals);
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
const MeterClass* const Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
@ -107,6 +103,19 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_init(void) {
/* no platform-specific setup needed */
}
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
int Platform_getUptime() {
struct timeval bootTime, currTime;
int mib[2] = { CTL_KERN, KERN_BOOTTIME };

View File

@ -27,10 +27,14 @@ extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;
void Platform_setBindings(Htop_Action* keys);
extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);

View File

@ -90,10 +90,6 @@ const SignalItem Platform_signals[] = {
const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals);
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
const MeterClass* const Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
@ -127,6 +123,19 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_init(void) {
/* no platform-specific setup needed */
}
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
int Platform_getUptime() {
struct timeval bootTime, currTime;
int mib[2] = { CTL_KERN, KERN_BOOTTIME };

View File

@ -29,10 +29,14 @@ extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;
void Platform_setBindings(Htop_Action* keys);
extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);

63
htop.c
View File

@ -34,18 +34,12 @@ in the source distribution for its full text.
#include "UsersTable.h"
#include "XUtils.h"
#ifdef HAVE_LIBSENSORS
#include <sensors/sensors.h>
#endif
static void printVersionFlag(void) {
fputs("htop " VERSION "\n", stdout);
fputs(PACKAGE " " VERSION "\n", stdout);
}
static void printHelpFlag(void) {
fputs("htop " VERSION "\n"
fputs(PACKAGE " " VERSION "\n"
COPYRIGHT "\n"
"Released under the GNU GPLv2.\n\n"
"-C --no-color Use a monochrome color scheme\n"
@ -62,8 +56,8 @@ static void printHelpFlag(void) {
"-V --version Print version info\n"
"\n"
"Long options may be passed with a single dash.\n\n"
"Press F1 inside htop for online help.\n"
"See 'man htop' for more information.\n",
"Press F1 inside " PACKAGE " for online help.\n"
"See 'man " PACKAGE "' for more information.\n",
stdout);
}
@ -269,22 +263,16 @@ static void setCommFilter(State* state, char** commFilter) {
int main(int argc, char** argv) {
char *lc_ctype = getenv("LC_CTYPE");
if (lc_ctype != NULL) {
if (lc_ctype != NULL)
setlocale(LC_CTYPE, lc_ctype);
} else if ((lc_ctype = getenv("LC_ALL"))) {
else if ((lc_ctype = getenv("LC_ALL")))
setlocale(LC_CTYPE, lc_ctype);
} else {
else
setlocale(LC_CTYPE, "");
}
CommandLineSettings flags = parseArguments(argc, argv); // may exit()
CommandLineSettings flags = parseArguments(argc, argv);
#ifdef HTOP_LINUX
if (access(PROCDIR, R_OK) != 0) {
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
exit(1);
}
#endif
Platform_init();
Process_setupColumnWidths();
@ -298,31 +286,21 @@ int main(int argc, char** argv) {
Header_populateFromSettings(header);
if (flags.delay != -1) {
if (flags.delay != -1)
settings->delay = flags.delay;
}
if (!flags.useColors) {
if (!flags.useColors)
settings->colorScheme = COLORSCHEME_MONOCHROME;
}
if (!flags.enableMouse) {
if (!flags.enableMouse)
settings->enableMouse = false;
}
if (flags.treeView) {
if (flags.treeView)
settings->treeView = true;
}
if (flags.highlightChanges) {
if (flags.highlightChanges)
settings->highlightChanges = true;
}
if (flags.highlightDelaySecs != -1) {
if (flags.highlightDelaySecs != -1)
settings->highlightDelaySecs = flags.highlightDelaySecs;
}
CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode);
#ifdef HAVE_LIBSENSORS
sensors_init(NULL);
#endif
MainPanel* panel = MainPanel_new();
ProcessList_setPanel(pl, (Panel*) panel);
@ -345,9 +323,8 @@ int main(int argc, char** argv) {
};
MainPanel_setState(panel, &state);
if (flags.commFilter) {
if (flags.commFilter)
setCommFilter(&state, &(flags.commFilter));
}
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, &state, true);
ScreenManager_add(scr, (Panel*) panel, -1);
@ -363,9 +340,7 @@ int main(int argc, char** argv) {
attroff(CRT_colors[RESET_COLOR]);
refresh();
#ifdef HAVE_LIBSENSORS
sensors_cleanup();
#endif
Platform_done();
CRT_done();
if (settings->changed)
@ -379,8 +354,8 @@ int main(int argc, char** argv) {
UsersTable_delete(ut);
Settings_delete(settings);
if(flags.pidMatchList) {
if (flags.pidMatchList)
Hashtable_delete(flags.pidMatchList);
}
return 0;
}

View File

@ -61,11 +61,12 @@ in the source distribution for its full text.
#include "zfs/ZfsArcStats.h"
#include "zfs/ZfsCompressedArcMeter.h"
#ifdef HAVE_LIBSENSORS
#include <sensors/sensors.h>
#endif
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
int Platform_numberOfFields = LAST_PROCESSFIELD;
const SignalItem Platform_signals[] = {
@ -112,6 +113,23 @@ static time_t Platform_Battery_cacheTime;
static double Platform_Battery_cacheLevel = NAN;
static ACPresence Platform_Battery_cacheIsOnAC;
void Platform_init(void) {
if (access(PROCDIR, R_OK) != 0) {
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
exit(1);
}
#ifdef HAVE_LIBSENSORS
sensors_init(NULL);
#endif
}
void Platform_done(void) {
#ifdef HAVE_LIBSENSORS
sensors_cleanup();
#endif
}
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
Panel* panel = st->panel;

View File

@ -26,10 +26,14 @@ extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;
void Platform_setBindings(Htop_Action* keys);
extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);

View File

@ -89,10 +89,6 @@ const SignalItem Platform_signals[] = {
const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals);
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
const MeterClass* const Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
@ -122,6 +118,19 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_init(void) {
/* no platform-specific setup needed */
}
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
// preserved from FreeBSD port
int Platform_getUptime() {
struct timeval bootTime, currTime;

View File

@ -28,10 +28,14 @@ extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;
void Platform_setBindings(Htop_Action* keys);
extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);

View File

@ -119,14 +119,23 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
int Platform_numberOfFields = LAST_PROCESSFIELD;
extern char Process_pidFormat[20];
void Platform_init(void) {
/* no platform-specific setup needed */
}
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
int Platform_getUptime() {
int boot_time = 0;
int curr_time = time(NULL);

View File

@ -45,12 +45,16 @@ extern ProcessField Platform_defaultFields[];
extern const MeterClass* const Platform_meterTypes[];
void Platform_setBindings(Htop_Action* keys);
extern int Platform_numberOfFields;
extern char Process_pidFormat[20];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);

View File

@ -88,18 +88,25 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
void Platform_setBindings(Htop_Action* keys) {
(void) keys;
}
int Platform_numberOfFields = 100;
extern char Process_pidFormat[20];
ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
void Platform_init(void) {
/* no platform-specific setup needed */
}
void Platform_done(void) {
/* no platform-specific cleanup needed */
}
void Platform_setBindings(Htop_Action* keys) {
/* no platform-specific key bindings */
(void) keys;
}
int Platform_getUptime() {
return 0;
}

View File

@ -25,14 +25,18 @@ extern ProcessFieldData Process_fields[];
extern const MeterClass* const Platform_meterTypes[];
void Platform_setBindings(Htop_Action* keys);
extern int Platform_numberOfFields;
extern char Process_pidFormat[20];
extern ProcessPidColumn Process_pidColumns[];
void Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
int Platform_getUptime(void);
void Platform_getLoadAverage(double* one, double* five, double* fifteen);