summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-02-20 14:52:10 -0200
committerHisham Muhammad <hisham@gobolinux.org>2015-02-20 14:52:10 -0200
commit6f868b00c02ef241216e7b95e0a09c38760c2f16 (patch)
tree905037b792a89fd8a2f6781e2656edf73a0fa590
parentf97d1bc54af13e7c801bf6d83e95661f25695719 (diff)
Fix allocation of processes. Closes #166.
-rw-r--r--Process.c9
-rw-r--r--Process.h4
-rw-r--r--ProcessList.c1
-rw-r--r--ScreenManager.c12
-rw-r--r--linux/LinuxProcess.c16
-rw-r--r--linux/LinuxProcess.h6
-rw-r--r--linux/LinuxProcessList.c5
-rw-r--r--linux/Platform.c1
-rw-r--r--linux/Platform.h1
9 files changed, 31 insertions, 24 deletions
diff --git a/Process.c b/Process.c
index 31dd9659..2ca7a147 100644
--- a/Process.c
+++ b/Process.c
@@ -647,14 +647,12 @@ static void Process_display(Object* cast, RichString* out) {
assert(out->chlen > 0);
}
-void Process_delete(Object* cast) {
- Process* this = (Process*) cast;
+void Process_done(Process* this) {
assert (this != NULL);
free(this->comm);
#ifdef HAVE_CGROUP
free(this->cgroup);
#endif
- free(this);
}
ObjectClass Process_class = {
@@ -664,9 +662,7 @@ ObjectClass Process_class = {
.compare = Process_compare
};
-Process* Process_new(struct Settings_* settings) {
- Process* this = calloc(1, sizeof(Process));
- Object_setClass(this, Class(Process));
+void Process_init(Process* this, struct Settings_* settings) {
this->pid = 0;
this->settings = settings;
this->tag = false;
@@ -682,7 +678,6 @@ Process* Process_new(struct Settings_* settings) {
this->cgroup = NULL;
#endif
if (Process_getuid == -1) Process_getuid = getuid();
- return this;
}
void Process_toggleTag(Process* this) {
diff --git a/Process.h b/Process.h
index 489769c7..38cbaaef 100644
--- a/Process.h
+++ b/Process.h
@@ -191,11 +191,11 @@ void Process_setupColumnWidths();
void Process_writeDefaultField(Process* this, RichString* str, ProcessField field);
-void Process_delete(Object* cast);
+void Process_done(Process* this);
extern ObjectClass Process_class;
-Process* Process_new(struct Settings_* settings);
+void Process_init(Process* this, struct Settings_* settings);
void Process_toggleTag(Process* this);
diff --git a/ProcessList.c b/ProcessList.c
index 74c3302a..e4bdb07d 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -241,7 +241,6 @@ void ProcessList_expandTree(ProcessList* this) {
}
void ProcessList_rebuildPanel(ProcessList* this) {
- int following = this->following;
const char* incFilter = this->incFilter;
int currPos = Panel_getSelectedIndex(this->panel);
diff --git a/ScreenManager.c b/ScreenManager.c
index 3df812c3..65910c38 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -158,26 +158,20 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
timeToRecalculate = (newTime - oldTime > this->settings->delay);
if (newTime < oldTime) timeToRecalculate = true; // clock was adjusted?
-//fprintf(stderr, "\n%p %f ", this, newTime);
if (doRefresh) {
if (timeToRecalculate || forceRecalculate) {
ProcessList_scan(this->header->pl);
-//fprintf(stderr, "scan ");
}
-//fprintf(stderr, "sortTo=%d ", sortTimeout);
if (sortTimeout == 0 || this->settings->treeView) {
ProcessList_sort(this->header->pl);
-//fprintf(stderr, "sort ");
sortTimeout = 1;
}
//this->header->pl->incFilter = IncSet_filter(inc);
ProcessList_rebuildPanel(this->header->pl);
-//fprintf(stderr, "rebuild ");
drawPanel = true;
}
if (timeToRecalculate || forceRecalculate) {
Header_draw(this->header);
-//fprintf(stderr, "drawHeader ");
oldTime = newTime;
forceRecalculate = false;
}
@@ -188,7 +182,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
for (int i = 0; i < panels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i);
Panel_draw(panel, i == focus);
-//fprintf(stderr, "drawPanel ");
if (i < panels) {
if (this->orientation == HORIZONTAL) {
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
@@ -206,8 +199,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
int prevCh = ch;
ch = getch();
-//fprintf(stderr, "ch=%d ", ch);
-
if (ch == KEY_MOUSE) {
MEVENT mevent;
int ok = getmouse(&mevent);
@@ -260,7 +251,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
} else
closeTimeout = 0;
drawPanel = false;
-//fprintf(stderr, "err ");
continue;
}
drawPanel = true;
@@ -300,12 +290,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
quit = true;
continue;
default:
-//fprintf(stderr, "onKey ");
sortTimeout = resetSortTimeout;
Panel_onKey(panelFocus, ch);
break;
}
-//fprintf(stderr, "loop ");
}
if (lastFocus)
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index 8a67f608..401a4836 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "LinuxProcess.h"
#include "CRT.h"
+#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
@@ -22,8 +23,23 @@ typedef struct LinuxProcess_ {
IOPriority ioPriority;
} LinuxProcess;
+#define Process_delete LinuxProcess_delete
+
}*/
+LinuxProcess* LinuxProcess_new(Settings* settings) {
+ LinuxProcess* this = calloc(sizeof(LinuxProcess), 1);
+ Process_init(&this->super, settings);
+ return this;
+}
+
+void LinuxProcess_delete(Object* cast) {
+ LinuxProcess* this = (LinuxProcess*) this;
+ Object_setClass(this, Class(Process));
+ Process_done((Process*)cast);
+ free(this);
+}
+
/*
[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
diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h
index beafff64..41a82c26 100644
--- a/linux/LinuxProcess.h
+++ b/linux/LinuxProcess.h
@@ -17,6 +17,12 @@ typedef struct LinuxProcess_ {
IOPriority ioPriority;
} LinuxProcess;
+#define Process_delete LinuxProcess_delete
+
+
+LinuxProcess* LinuxProcess_new(Settings* settings);
+
+void LinuxProcess_delete(Object* cast);
/*
[1] Note that before kernel 2.6.26 a process that has not asked for
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index aed530dd..2bb207ee 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -375,6 +375,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
int nFields;
char** fields = String_split(trimmed, ':', &nFields);
free(trimmed);
+ free(process->cgroup);
if (nFields >= 3) {
process->cgroup = strndup(fields[2] + 1, 10);
} else {
@@ -521,7 +522,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
process = existingProcess;
assert(process->pid == pid);
} else {
- process = Process_new(settings);
+ process = (Process*) LinuxProcess_new(settings);
assert(process->comm == NULL);
process->pid = pid;
process->tgid = parent ? parent->pid : pid;
@@ -625,7 +626,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
if (existingProcess)
ProcessList_remove((ProcessList*)this, process);
else
- Process_delete((Object*)process);
+ LinuxProcess_delete((Object*)process);
}
}
closedir(dir);
diff --git a/linux/Platform.c b/linux/Platform.c
index 0a763362..8d3e2976 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -29,6 +29,7 @@ in the source distribution for its full text.
#include "Action.h"
#include "MainPanel.h"
#include "BatteryMeter.h"
+#include "LinuxProcess.h"
}*/
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
diff --git a/linux/Platform.h b/linux/Platform.h
index c4a5cd24..de7ca919 100644
--- a/linux/Platform.h
+++ b/linux/Platform.h
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include "Action.h"
#include "MainPanel.h"
#include "BatteryMeter.h"
+#include "LinuxProcess.h"
void Platform_setBindings(Htop_Action* keys);

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