aboutsummaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:30 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:30 +0200
commite2b58f0ab81b2aafeb8c29a69abad7829fa21ab3 (patch)
treec4e410dd878ceed9fc058d14bad8011b423212fe /ProcessList.c
parenteaf11cc12a1aa4b050a8a1e7ea3770d3d9c81e95 (diff)
downloaddebian_htop-e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3.tar.gz
debian_htop-e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3.tar.bz2
debian_htop-e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3.zip
Imported Upstream version 1.0.1upstream/1.0.1
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c84
1 files changed, 68 insertions, 16 deletions
diff --git a/ProcessList.c b/ProcessList.c
index be01ca6..1f47408 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -5,19 +5,13 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
-#ifndef CONFIG_H
-#define CONFIG_H
-#include "config.h"
-#endif
-
#include "ProcessList.h"
-#include "Process.h"
-#include "Vector.h"
-#include "UsersTable.h"
-#include "Hashtable.h"
+
+#include "CRT.h"
#include "String.h"
-#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/utsname.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
@@ -25,14 +19,19 @@ in the source distribution for its full text.
#include <stdio.h>
#include <signal.h>
#include <stdbool.h>
-#include <sys/utsname.h>
#include <stdarg.h>
#include <math.h>
-
-#include "debug.h"
+#include <string.h>
+#include <time.h>
#include <assert.h>
/*{
+#include "Vector.h"
+#include "Hashtable.h"
+#include "UsersTable.h"
+#include "Panel.h"
+#include "Process.h"
+#include <sys/types.h>
#ifndef PROCDIR
#define PROCDIR "/proc"
@@ -109,6 +108,13 @@ typedef struct ProcessList_ {
Hashtable* processTable;
UsersTable* usersTable;
+ Panel* panel;
+ int following;
+ bool userOnly;
+ uid_t userId;
+ bool filtering;
+ const char* incFilter;
+
int cpuCount;
int totalTasks;
int userlandThreads;
@@ -243,6 +249,10 @@ void ProcessList_delete(ProcessList* this) {
free(this);
}
+void ProcessList_setPanel(ProcessList* this, Panel* panel) {
+ this->panel = panel;
+}
+
void ProcessList_invertSortOrder(ProcessList* this) {
if (this->direction == 1)
this->direction = -1;
@@ -605,7 +615,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
command[amtRead] = '\0';
fclose(file);
free(process->comm);
- process->comm = String_copy(command);
+ process->comm = strdup(command);
return true;
}
@@ -698,11 +708,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
if (process->state == 'Z') {
free(process->comm);
- process->comm = String_copy(command);
+ process->comm = strdup(command);
} else if (Process_isThread(process)) {
if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
free(process->comm);
- process->comm = String_copy(command);
+ process->comm = strdup(command);
} else if (this->showingThreadNames) {
if (! ProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess;
@@ -888,3 +898,45 @@ void ProcessList_expandTree(ProcessList* this) {
process->showChildren = true;
}
}
+
+void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) {
+ if (!flags) {
+ following = this->following;
+ userOnly = this->userOnly;
+ userId = this->userId;
+ filtering = this->filtering;
+ incFilter = this->incFilter;
+ } else {
+ this->following = following;
+ this->userOnly = userOnly;
+ this->userId = userId;
+ this->filtering = filtering;
+ this->incFilter = incFilter;
+ }
+
+ int currPos = Panel_getSelectedIndex(this->panel);
+ pid_t currPid = following ? following : 0;
+ int currScrollV = this->panel->scrollV;
+
+ Panel_prune(this->panel);
+ int size = ProcessList_size(this);
+ int idx = 0;
+ for (int i = 0; i < size; i++) {
+ bool hidden = false;
+ Process* p = ProcessList_get(this, i);
+
+ if ( (!p->show)
+ || (userOnly && (p->st_uid != userId))
+ || (filtering && !(String_contains_i(p->comm, incFilter))) )
+ hidden = true;
+
+ if (!hidden) {
+ Panel_set(this->panel, idx, (Object*)p);
+ if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) {
+ Panel_setSelected(this->panel, idx);
+ this->panel->scrollV = currScrollV;
+ }
+ idx++;
+ }
+ }
+}

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