Commit eb229d9a authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Changes for supporting separate platform subdirectories.

parent 1eda099d
/*
htop - Action.c
(C) 2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Process.h"
#include "Panel.h"
#include "Action.h"
/*{
#include "IncSet.h"
#include "Settings.h"
#include "UsersTable.h"
typedef enum {
HTOP_OK = 0x00,
HTOP_REFRESH = 0x01,
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
HTOP_SAVE_SETTINGS = 0x04,
HTOP_KEEP_FOLLOWING = 0x08,
HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
} Htop_Reaction;
typedef Htop_Reaction (*Htop_Action)();
typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
} State;
typedef bool(*Action_ForeachProcessFn)(Process*, size_t);
}*/
bool Action_foreachProcess(Panel* panel, Action_ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
bool ok = true;
bool anyTagged = false;
for (int i = 0; i < Panel_size(panel); i++) {
Process* p = (Process*) Panel_get(panel, i);
if (p->tag) {
ok = fn(p, arg) && ok;
anyTagged = true;
}
}
if (!anyTagged) {
Process* p = (Process*) Panel_getSelected(panel);
if (p) ok = fn(p, arg) && ok;
}
if (wasAnyTagged)
*wasAnyTagged = anyTagged;
return ok;
}
/* Do not edit this file. It was automatically generated. */
#ifndef HEADER_Action
#define HEADER_Action
/*
htop - Action.h
(C) 2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "IncSet.h"
#include "Settings.h"
#include "UsersTable.h"
typedef enum {
HTOP_OK = 0x00,
HTOP_REFRESH = 0x01,
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
HTOP_SAVE_SETTINGS = 0x04,
HTOP_KEEP_FOLLOWING = 0x08,
HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
} Htop_Reaction;
typedef Htop_Reaction (*Htop_Action)();
typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
} State;
typedef bool(*Action_ForeachProcessFn)(Process*, size_t);
bool Action_foreachProcess(Panel* panel, Action_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
#endif
...@@ -7,7 +7,6 @@ in the source distribution for its full text. ...@@ -7,7 +7,6 @@ in the source distribution for its full text.
#include "CRT.h" #include "CRT.h"
#include "config.h"
#include "String.h" #include "String.h"
#include "RichString.h" #include "RichString.h"
...@@ -16,9 +15,6 @@ in the source distribution for its full text. ...@@ -16,9 +15,6 @@ in the source distribution for its full text.
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
...@@ -112,6 +108,8 @@ typedef enum ColorElements_ { ...@@ -112,6 +108,8 @@ typedef enum ColorElements_ {
void CRT_fatalError(const char* note) __attribute__ ((noreturn)); void CRT_fatalError(const char* note) __attribute__ ((noreturn));
void CRT_handleSIGSEGV(int sgn);
}*/ }*/
// TODO: centralize these in Settings. // TODO: centralize these in Settings.
...@@ -134,27 +132,6 @@ char* CRT_termType; ...@@ -134,27 +132,6 @@ char* CRT_termType;
void *backtraceArray[128]; void *backtraceArray[128];
static void CRT_handleSIGSEGV(int sgn) {
(void) sgn;
CRT_done();
#if __linux
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
#ifdef HAVE_EXECINFO_H
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
backtrace_symbols_fd(backtraceArray, size, 2);
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
#endif
#else
fprintf(stderr, "\n\nhtop " VERSION " aborting. Unsupported platform.\n");
#endif
abort();
}
static void CRT_handleSIGTERM(int sgn) { static void CRT_handleSIGTERM(int sgn) {
(void) sgn; (void) sgn;
CRT_done(); CRT_done();
......
...@@ -9,9 +9,6 @@ Released under the GNU GPL, see the COPYING file ...@@ -9,9 +9,6 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#ifdef HAVE_EXECINFO_H
#endif
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
#define COLORSCHEME_DEFAULT 0 #define COLORSCHEME_DEFAULT 0
...@@ -103,6 +100,8 @@ typedef enum ColorElements_ { ...@@ -103,6 +100,8 @@ typedef enum ColorElements_ {
void CRT_fatalError(const char* note) __attribute__ ((noreturn)); void CRT_fatalError(const char* note) __attribute__ ((noreturn));
void CRT_handleSIGSEGV(int sgn);
// TODO: centralize these in Settings. // TODO: centralize these in Settings.
......
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS = htop bin_PROGRAMS = htop
dist_man_MANS = htop.1 dist_man_MANS = htop.1
EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \ EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \
install-sh autogen.sh missing install-sh autogen.sh missing
...@@ -10,7 +12,7 @@ applications_DATA = htop.desktop ...@@ -10,7 +12,7 @@ applications_DATA = htop.desktop
pixmapdir = $(datadir)/pixmaps pixmapdir = $(datadir)/pixmaps
pixmap_DATA = htop.png pixmap_DATA = htop.png
htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)"
AM_CPPFLAGS = -DNDEBUG AM_CPPFLAGS = -DNDEBUG
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
...@@ -18,23 +20,42 @@ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \ ...@@ -18,23 +20,42 @@ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
IOPriorityPanel.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
HostnameMeter.c OpenFilesScreen.c Affinity.c IOPriority.c IncSet.c HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
IOPriorityPanel.h CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \ CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \ ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
TraceScreen.h UptimeMeter.h UsersTable.h Vector.h Process.h AffinityPanel.h \ TraceScreen.h UptimeMeter.h UsersTable.h Vector.h Process.h AffinityPanel.h \
HostnameMeter.h OpenFilesScreen.h Affinity.h IOPriority.h IncSet.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h
if HTOP_LINUX
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
linux/LinuxProcessList.c linux/LinuxCRT.c
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
linux/LinuxProcessList.h linux/LinuxCRT.h
endif
if HTOP_UNSUPPORTED
myhtopplatsources = unsupported/Platform.c unsupported/UnsupportedProcessList.c \
unsupported/UnsupportedCRT.c
myhtopplatheaders = unsupported/Platform.h unsupported/UnsupportedProcessList.h \
unsupported/UnsupportedCRT.h
endif
SUFFIXES = .h SUFFIXES = .h
BUILT_SOURCES = $(myhtopheaders) BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
target:
echo $(htop_SOURCES)
profile: profile:
$(MAKE) all CFLAGS="-pg" AM_CPPFLAGS="-pg -O2 -DNDEBUG" $(MAKE) all CFLAGS="-pg" AM_CPPFLAGS="-pg -O2 -DNDEBUG"
...@@ -47,3 +68,4 @@ debug: ...@@ -47,3 +68,4 @@ debug:
cppcheck: cppcheck:
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
/* /*
htop - Process.c htop - Process.c
(C) 2004-2011 Hisham H. Muhammad (C) 2004-2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
...@@ -32,7 +32,7 @@ in the source distribution for its full text. ...@@ -32,7 +32,7 @@ in the source distribution for its full text.
#include <hwloc/linux.h> #include <hwloc/linux.h>
#endif #endif
// This works only with glibc 2.1+. On earlier versions // On Linux, this works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size. // the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE #ifndef PAGE_SIZE
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) ) #define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
...@@ -42,7 +42,7 @@ in the source distribution for its full text. ...@@ -42,7 +42,7 @@ in the source distribution for its full text.
/*{ /*{
#include "Object.h" #include "Object.h"
#include "Affinity.h" #include "Affinity.h"
#include "IOPriority.h"
#include <sys/types.h> #include <sys/types.h>
#define PROCESS_FLAG_IO 1 #define PROCESS_FLAG_IO 1
...@@ -122,7 +122,6 @@ typedef struct Process_ { ...@@ -122,7 +122,6 @@ typedef struct Process_ {
long int priority; long int priority;
long int nice; long int nice;
long int nlwp; long int nlwp;
IOPriority ioPriority;
char starttime_show[8]; char starttime_show[8];
time_t starttime_ctime; time_t starttime_ctime;
...@@ -628,24 +627,6 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel ...@@ -628,24 +627,6 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
#ifdef HAVE_OOM #ifdef HAVE_OOM
case OOM: snprintf(buffer, n, Process_pidFormat, this->oom); break; case OOM: snprintf(buffer, n, Process_pidFormat, this->oom); break;
#endif #endif
case IO_PRIORITY: {
int klass = IOPriority_class(this->ioPriority);
if (klass == IOPRIO_CLASS_NONE) {
// see note [1] above
snprintf(buffer, n, "B%1d ", (int) (this->nice + 20) / 5);
} else if (klass == IOPRIO_CLASS_BE) {
snprintf(buffer, n, "B%1d ", IOPriority_data(this->ioPriority));
} else if (klass == IOPRIO_CLASS_RT) {
attr = CRT_colors[PROCESS_HIGH_PRIORITY];
snprintf(buffer, n, "R%1d ", IOPriority_data(this->ioPriority));
} else if (this->ioPriority == IOPriority_Idle) {
attr = CRT_colors[PROCESS_LOW_PRIORITY];
snprintf(buffer, n, "id ");
} else {
snprintf(buffer, n, "?? ");
}
break;
}
default: default:
snprintf(buffer, n, "- "); snprintf(buffer, n, "- ");
} }
...@@ -720,27 +701,6 @@ bool Process_changePriorityBy(Process* this, size_t delta) { ...@@ -720,27 +701,6 @@ bool Process_changePriorityBy(Process* this, size_t delta) {
return Process_setPriority(this, this->nice + delta); return Process_setPriority(this, this->nice + delta);
} }
IOPriority Process_updateIOPriority(Process* this) {
IOPriority ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, this->pid);
this->ioPriority = ioprio;
return ioprio;
}
bool Process_setIOPriority(Process* this, IOPriority ioprio) {
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->pid, ioprio);
return (Process_updateIOPriority(this) == ioprio);
}
/*
[1] Note that before kernel 2.6.26 a process that has not asked for
an io priority formally uses "none" as scheduling class, but the
io scheduler will treat such processes as if it were in the best
effort class. The priority within the best effort class will be
dynamically derived from the cpu nice level of the process:
io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page
*/
#define Process_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->nice + 20) / 5) : p_->ioPriority)
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
Affinity* Process_getAffinity(Process* this) { Affinity* Process_getAffinity(Process* this) {
...@@ -902,8 +862,6 @@ long Process_compare(const void* v1, const void* v2) { ...@@ -902,8 +862,6 @@ long Process_compare(const void* v1, const void* v2) {
case OOM: case OOM:
return (p1->oom - p2->oom); return (p1->oom - p2->oom);
#endif #endif
case IO_PRIORITY:
return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2);
default: default:
return (p1->pid - p2->pid); return (p1->pid - p2->pid);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#define HEADER_Process #define HEADER_Process
/* /*
htop - Process.h htop - Process.h
(C) 2004-2011 Hisham H. Muhammad (C) 2004-2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
...@@ -12,7 +12,7 @@ in the source distribution for its full text. ...@@ -12,7 +12,7 @@ in the source distribution for its full text.
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
#endif #endif
// This works only with glibc 2.1+. On earlier versions // On Linux, this works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size. // the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE #ifndef PAGE_SIZE
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) ) #define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
...@@ -21,7 +21,7 @@ in the source distribution for its full text. ...@@ -21,7 +21,7 @@ in the source distribution for its full text.
#include "Object.h" #include "Object.h"
#include "Affinity.h" #include "Affinity.h"
#include "IOPriority.h"
#include <sys/types.h> #include <sys/types.h>
#define PROCESS_FLAG_IO 1 #define PROCESS_FLAG_IO 1
...@@ -101,7 +101,6 @@ typedef struct Process_ { ...@@ -101,7 +101,6 @@ typedef struct Process_ {
long int priority; long int priority;
long int nice; long int nice;
long int nlwp; long int nlwp;
IOPriority ioPriority;
char starttime_show[8]; char starttime_show[8];
time_t starttime_ctime; time_t starttime_ctime;
...@@ -202,20 +201,6 @@ bool Process_setPriority(Process* this, int priority); ...@@ -202,20 +201,6 @@ bool Process_setPriority(Process* this, int priority);
bool Process_changePriorityBy(Process* this, size_t delta); bool Process_changePriorityBy(Process* this, size_t delta);
IOPriority Process_updateIOPriority(Process* this);
bool Process_setIOPriority(Process* this, IOPriority ioprio);
/*
[1] Note that before kernel 2.6.26 a process that has not asked for
an io priority formally uses "none" as scheduling class, but the
io scheduler will treat such processes as if it were in the best
effort class. The priority within the best effort class will be
dynamically derived from the cpu nice level of the process:
extern io_priority;
*/
#define Process_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->nice + 20) / 5) : p_->ioPriority)
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
Affinity* Process_getAffinity(Process* this); Affinity* Process_getAffinity(Process* this);
......
This diff is collapsed.
...@@ -15,18 +15,6 @@ in the source distribution for its full text. ...@@ -15,18 +15,6 @@ in the source distribution for its full text.
#include "Panel.h" #include "Panel.h"
#include "Process.h" #include "Process.h"
#ifndef PROCDIR
#define PROCDIR "/proc"
#endif
#ifndef PROCSTATFILE
#define PROCSTATFILE PROCDIR "/stat"
#endif
#ifndef PROCMEMINFOFILE
#define PROCMEMINFOFILE PROCDIR "/meminfo"
#endif
#ifndef MAX_NAME #ifndef MAX_NAME
#define MAX_NAME 128 #define MAX_NAME 128
#endif #endif
...@@ -135,12 +123,15 @@ typedef struct ProcessList_ { ...@@ -135,12 +123,15 @@ typedef struct ProcessList_ {
} ProcessList; } ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList);
void ProcessList_scan(ProcessList* pl);
extern const char *ProcessList_treeStrAscii[TREE_STR_COUNT]; extern const char *ProcessList_treeStrAscii[TREE_STR_COUNT];
extern const char *ProcessList_treeStrUtf8[TREE_STR_COUNT]; extern const char *ProcessList_treeStrUtf8[TREE_STR_COUNT];
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList); ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList);
void ProcessList_delete(ProcessList* this); void ProcessList_delete(ProcessList* this);
...@@ -150,39 +141,21 @@ void ProcessList_invertSortOrder(ProcessList* this); ...@@ -150,39 +141,21 @@ void ProcessList_invertSortOrder(ProcessList* this);
void ProcessList_printHeader(ProcessList* this, RichString* header); void ProcessList_printHeader(ProcessList* this, RichString* header);
void ProcessList_add(ProcessList* this, Process* p);
void ProcessList_remove(ProcessList* this, Process* p);
Process* ProcessList_get(ProcessList* this, int idx); Process* ProcessList_get(ProcessList* this, int idx);
int ProcessList_size(ProcessList* this); int ProcessList_size(ProcessList* this);
void ProcessList_sort(ProcessList* this); void ProcessList_sort(ProcessList* this);
#ifdef HAVE_TASKSTATS
#endif
#ifdef HAVE_OPENVZ
#endif
#ifdef HAVE_CGROUP
#endif
#ifdef HAVE_VSERVER
#endif
#ifdef HAVE_OOM
#endif
void ProcessList_scan(ProcessList* this);
ProcessField ProcessList_keyAt(ProcessList* this, int at); ProcessField ProcessList_keyAt(ProcessList* this, int at);
void ProcessList_expandTree(ProcessList* this); void ProcessList_expandTree(ProcessList* this);
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter); void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter);
#endif #endif
...@@ -174,4 +174,4 @@ void RichString_appendn(RichString* this, int attrs, const char* data, int len) ...@@ -174,4 +174,4 @@ void RichString_appendn(RichString* this, int attrs, const char* data, int len)
void RichString_write(RichString* this, int attrs, const char* data) { void RichString_write(RichString* this, int attrs, const char* data) {
RichString_writeFrom(this, attrs, data, 0, strlen(data)); RichString_writeFrom(this, attrs, data, 0, strlen(data));
} }
\ No newline at end of file
...@@ -22,6 +22,19 @@ AC_DISABLE_SHARED ...@@ -22,6 +22,19 @@ AC_DISABLE_SHARED
AC_ENABLE_STATIC AC_ENABLE_STATIC
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
# Checks for platform.
# ----------------------------------------------------------------------
case "$target" in
*linux*)
my_htop_platform=linux
;;
*)
my_htop_platform=unsupported
;;
esac
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
# Checks for libraries. # Checks for libraries.
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"]) AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
...@@ -60,17 +73,25 @@ CFLAGS="$save_cflags" ...@@ -60,17 +73,25 @@ CFLAGS="$save_cflags"
# Checks for features and flags. # Checks for features and flags.
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
PROCDIR=/proc PROCDIR=/proc
AC_ARG_ENABLE(proc, [AC_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no")
if test "x$enable_proc" = xyes; then
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
fi
AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).], AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).],
if test -n "$withval"; then if test -n "$withval"; then
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem]) AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
PROCDIR="$withval" PROCDIR="$withval"
fi, fi,
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem])) AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
if test "x$cross_compiling" = xno; then if test "x$cross_compiling" = xno; then
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) if test "x$enable_proc" = xyes; then
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find $PROCDIR/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find $PROCDIR/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
fi
fi fi
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no") AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
...@@ -161,5 +182,6 @@ fi ...@@ -161,5 +182,6 @@ fi
# We're done, let's go! # We're done, let's go!
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
AC_SUBST(my_htop_platform)
AC_CONFIG_FILES([Makefile htop.1]) AC_CONFIG_FILES([Makefile htop.1])
AC_OUTPUT AC_OUTPUT
...@@ -22,8 +22,9 @@ in the source distribution for its full text. ...@@ -22,8 +22,9 @@ in the source distribution for its full text.
#include "TraceScreen.h" #include "TraceScreen.h"
#include "OpenFilesScreen.h" #include "OpenFilesScreen.h"
#include "AffinityPanel.h" #include "AffinityPanel.h"
#include "IOPriorityPanel.h" #include "Platform.h"
#include "IncSet.h" #include "IncSet.h"
#include "Action.h"
#include "htop.h" #include "htop.h"
#include <unistd.h> #include <unistd.h>
...@@ -43,31 +44,6 @@ in the source distribution for its full text. ...@@ -43,31 +44,6 @@ in the source distribution for its full text.
#define COPYRIGHT "(C) 2004-2014 Hisham Muhammad" #define COPYRIGHT "(C) 2004-2014 Hisham Muhammad"
/*{
typedef enum {
HTOP_OK = 0x00,
HTOP_REFRESH = 0x01,
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
HTOP_SAVE_SETTINGS = 0x04,
HTOP_KEEP_FOLLOWING = 0x08,
HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
} Htop_Reaction;
typedef Htop_Reaction (*Htop_Action)();
typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
} State;
typedef bool(*ForeachProcessFn)(Process*, size_t);
}*/
static void printVersionFlag() { static void printVersionFlag() {
fputs("htop " VERSION " - " COPYRIGHT "\n" fputs("htop " VERSION " - " COPYRIGHT "\n"
"Released under the GNU GPL.\n\n", "Released under the GNU GPL.\n\n",
...@@ -211,28 +187,9 @@ static void Setup_run(Settings* settings, const Header* header) { ...@@ -211,28 +187,9 @@ static void Setup_run(Settings* settings, const Header* header) {
ScreenManager_delete(scr); ScreenManager_delete(scr);
} }
static bool foreachProcess(Panel* panel, ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
bool ok = true;
bool anyTagged = false;
for (int i = 0; i < Panel_size(panel); i++) {
Process* p = (Process*) Panel_get(panel, i);
if (p->tag) {
ok = fn(p, arg) && ok;
anyTagged = true;
}
}
if (!anyTagged) {
Process* p = (Process*) Panel_getSelected(panel);
if (p) ok = fn(p, arg) && ok;
}
if (wasAnyTagged)
*wasAnyTagged = anyTagged;
return ok;
}
static bool changePriority(Panel* panel, int delta) { static bool changePriority(Panel* panel, int delta) {
bool anyTagged; bool anyTagged;
bool ok = foreachProcess(panel, (ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged); bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
if (!ok) if (!ok)
beep(); beep();
return anyTagged; return anyTagged;
...@@ -429,24 +386,6 @@ static Htop_Reaction actionInvertSortOrder(Panel* panel, ProcessList* pl) { ...@@ -429,24 +386,6 @@ static Htop_Reaction actionInvertSortOrder(Panel* panel, ProcessList* pl) {
return HTOP_REFRESH | HTOP_SAVE_SETTINGS; return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
} }
static Htop_Reaction actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
(void) panel, (void) pl;
Process* p = (Process*) Panel_getSelected(panel);
if (!p) return HTOP_OK;
IOPriority ioprio = p->ioPriority;
Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
void* set = pickFromVector(panel, ioprioPanel, 21, fuFunctions, header);
if (set) {
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
bool ok = foreachProcess(panel, (ForeachProcessFn) Process_setIOPriority, (size_t) ioprio, NULL);
if (!ok)
beep();
}
Panel_delete((Object*)ioprioPanel);
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionSetSortColumn(Panel* panel, ProcessList* pl, Header* header) { static Htop_Reaction actionSetSortColumn(Panel* panel, ProcessList* pl, Header* header) {
return sortBy(panel, pl, header); return sortBy(panel, pl, header);
} }
...@@ -479,11 +418,14 @@ static Htop_Reaction actionSetAffinity(Panel* panel, ProcessList* pl, Header* he ...@@ -479,11 +418,14 @@ static Htop_Reaction actionSetAffinity(Panel* panel, ProcessList* pl, Header* he
void* set = pickFromVector(panel, affinityPanel, 15, fuFunctions, header); void* set = pickFromVector(panel, affinityPanel, 15, fuFunctions, header);
if (set) { if (set) {
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel); Affinity* affinity = AffinityPanel_getAffinity(affinityPanel);
bool ok = foreachProcess(panel, (ForeachProcessFn) Process_setAffinity, (size_t) affinity, NULL); bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) Process_setAffinity, (size_t) affinity, NULL);
if (!ok) beep(); if (!ok) beep();
Affinity_delete(affinity); Affinity_delete(affinity);
} }
Panel_delete((Object*)affinityPanel); Panel_delete((Object*)affinityPanel);
#else
(void) panel;
(void) header;
#endif #endif
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
} }
...@@ -498,7 +440,7 @@ static Htop_Reaction actionKill(Panel* panel, ProcessList* pl, Header* header) { ...@@ -498,7 +440,7 @@ static Htop_Reaction actionKill(Panel* panel, ProcessList* pl, Header* header) {
Panel_setHeader(panel, "Sending..."); Panel_setHeader(panel, "Sending...");
Panel_draw(panel, true); Panel_draw(panel, true);
refresh(); refresh();
foreachProcess(panel, (ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL); Action_foreachProcess(panel, (Action_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
napms(500); napms(500);
} }
} }
...@@ -596,7 +538,7 @@ static Htop_Reaction actionTagAllChildren(Panel* panel) { ...@@ -596,7 +538,7 @@ static Htop_Reaction actionTagAllChildren(Panel* panel) {
return HTOP_OK; return HTOP_OK;
} }
void setBindings(Htop_Action* keys) { static void setBindings(Htop_Action* keys) {
keys[KEY_RESIZE] = actionResize; keys[KEY_RESIZE] = actionResize;
keys['M'] = actionSortByMemory; keys['M'] = actionSortByMemory;
keys['T'] = actionSortByTime; keys['T'] = actionSortByTime;
...@@ -615,7 +557,6 @@ void setBindings(Htop_Action* keys) { ...@@ -615,7 +557,6 @@ void setBindings(Htop_Action* keys) {
keys['['] = actionLowerPriority; keys['['] = actionLowerPriority;
keys[KEY_F(8)] = actionLowerPriority; keys[KEY_F(8)] = actionLowerPriority;
keys['I'] = actionInvertSortOrder; keys['I'] = actionInvertSortOrder;
keys['i'] = actionSetIOPriority;
keys[KEY_F(6)] = actionExpandCollapseOrSortColumn; keys[KEY_F(6)] = actionExpandCollapseOrSortColumn;
keys[KEY_F(18)] = actionExpandCollapseOrSortColumn; keys[KEY_F(18)] = actionExpandCollapseOrSortColumn;
keys['<'] = actionSetSortColumn; keys['<'] = actionSetSortColumn;
...@@ -761,17 +702,7 @@ int main(int argc, char** argv) { ...@@ -761,17 +702,7 @@ int main(int argc, char** argv) {
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);
} }
bool quit = false;
int sortTimeout = 0;
int resetSortTimeout = 5;
bool doRefresh = true;
bool forceRecalculate = false;
Settings* settings;
ProcessList* pl = NULL;
UsersTable* ut = UsersTable_new();
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
char *locale = setlocale(LC_ALL, NULL); char *locale = setlocale(LC_ALL, NULL);
if (locale == NULL || locale[0] == '\0') if (locale == NULL || locale[0] == '\0')
...@@ -786,13 +717,14 @@ int main(int argc, char** argv) { ...@@ -786,13 +717,14 @@ int main(int argc, char** argv) {
CRT_utf8 = false; CRT_utf8 = false;
#endif #endif
pl = ProcessList_new(ut, pidWhiteList); UsersTable* ut = UsersTable_new();
ProcessList* pl = ProcessList_new(ut, pidWhiteList);
pl->userOnly = userOnly; pl->userOnly = userOnly;
pl->userId = userId; pl->userId = userId;
Process_getMaxPid(); Process_getMaxPid();
Header* header = Header_new(pl); Header* header = Header_new(pl);
settings = Settings_new(pl, header, pl->cpuCount); Settings* settings = Settings_new(pl, header, pl->cpuCount);
int headerHeight = Header_calculateHeight(header); int headerHeight = Header_calculateHeight(header);
// FIXME: move delay code to settings // FIXME: move delay code to settings
...@@ -839,12 +771,19 @@ int main(int argc, char** argv) { ...@@ -839,12 +771,19 @@ int main(int argc, char** argv) {
Htop_Action keys[KEY_MAX] = { NULL }; Htop_Action keys[KEY_MAX] = { NULL };
setBindings(keys); setBindings(keys);
Platform_setBindings(keys);
State state = { State state = {
.inc = inc, .inc = inc,
.settings = settings, .settings = settings,
.ut = ut, .ut = ut,
}; };
bool quit = false;
int sortTimeout = 0;
int resetSortTimeout = 5;
bool doRefresh = true;
bool forceRecalculate = false;
while (!quit) { while (!quit) {
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
......
...@@ -13,33 +13,8 @@ in the source distribution for its full text. ...@@ -13,33 +13,8 @@ in the source distribution for its full text.
#define COPYRIGHT "(C) 2004-2014 Hisham Muhammad" #define COPYRIGHT "(C) 2004-2014 Hisham Muhammad"
typedef enum {
HTOP_OK = 0x00,
HTOP_REFRESH = 0x01,
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
HTOP_SAVE_SETTINGS = 0x04,
HTOP_KEEP_FOLLOWING = 0x08,
HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
} Htop_Reaction;
typedef Htop_Reaction (*Htop_Action)();
typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
} State;
typedef bool(*ForeachProcessFn)(Process*, size_t);
// ---------------------------------------- // ----------------------------------------
void setBindings(Htop_Action* keys);
// ---------------------------------------- // ----------------------------------------
int main(int argc, char** argv); int main(int argc, char** argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment