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-23 01:13:40 -0300
commit9780c312f40633a2ce23300cc76faf64e07a87ed (patch)
tree1d04f7070e5183f6f9aad77c91d4d81025868a24
parentcce2202a1ffdce2d6d775e3d0d5ced092d823598 (diff)
Fix allocation of processes. Closes #166.
Conflicts: Process.c Process.h ProcessList.c ScreenManager.c linux/LinuxProcessList.c
-rw-r--r--BatteryMeter.c1
-rw-r--r--Process.c11
-rw-r--r--Process.h6
-rw-r--r--Settings.c4
-rw-r--r--Settings.h4
-rw-r--r--configure.ac3
-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
-rw-r--r--unsupported/Platform.c4
-rw-r--r--unsupported/Platform.h1
13 files changed, 48 insertions, 15 deletions
diff --git a/BatteryMeter.c b/BatteryMeter.c
index 5cd0c389..32be4571 100644
--- a/BatteryMeter.c
+++ b/BatteryMeter.c
@@ -13,6 +13,7 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
#include "ProcessList.h"
#include "CRT.h"
#include "String.h"
+#include "Platform.h"
#include <string.h>
#include <stdlib.h>
diff --git a/Process.c b/Process.c
index de25cbbb..dbdb4810 100644
--- a/Process.c
+++ b/Process.c
@@ -45,6 +45,8 @@ in the source distribution for its full text.
#include <sys/types.h>
+typedef struct Settings_ Settings;
+
#define PROCESS_FLAG_IO 1
#define PROCESS_FLAG_IOPRIO 2
#define PROCESS_FLAG_OPENVZ 4
@@ -643,14 +645,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 = {
@@ -660,9 +660,7 @@ ObjectClass Process_class = {
.compare = Process_compare
};
-Process* Process_new(struct ProcessList_ *pl) {
- Process* this = calloc(1, sizeof(Process));
- Object_setClass(this, Class(Process));
+void Process_init(Process* this, struct Settings_* settings, struct ProcessList_* pl) {
this->pid = 0;
this->pl = pl;
this->tag = false;
@@ -678,7 +676,6 @@ Process* Process_new(struct ProcessList_ *pl) {
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 6bd40686..f4d5a463 100644
--- a/Process.h
+++ b/Process.h
@@ -24,6 +24,8 @@ in the source distribution for its full text.
#include <sys/types.h>
+typedef struct Settings_ Settings;
+
#define PROCESS_FLAG_IO 1
#define PROCESS_FLAG_IOPRIO 2
#define PROCESS_FLAG_OPENVZ 4
@@ -189,11 +191,11 @@ void Process_setupColumnWidths();
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
-void Process_delete(Object* cast);
+void Process_done(Process* this);
extern ObjectClass Process_class;
-Process* Process_new(struct ProcessList_ *pl);
+void Process_init(Process* this, struct Settings_* settings, struct ProcessList_* pl);
void Process_toggleTag(Process* this);
diff --git a/Settings.c b/Settings.c
index 1dc8b1b2..52ab39eb 100644
--- a/Settings.c
+++ b/Settings.c
@@ -22,14 +22,14 @@ in the source distribution for its full text.
#include "Header.h"
#include <stdbool.h>
-typedef struct Settings_ {
+struct Settings_ {
char* userSettings;
ProcessList* pl;
Header* header;
int colorScheme;
int delay;
bool changed;
-} Settings;
+};
}*/
diff --git a/Settings.h b/Settings.h
index 28fe5520..2fe27abe 100644
--- a/Settings.h
+++ b/Settings.h
@@ -15,14 +15,14 @@ in the source distribution for its full text.
#include "Header.h"
#include <stdbool.h>
-typedef struct Settings_ {
+struct Settings_ {
char* userSettings;
ProcessList* pl;
Header* header;
int colorScheme;
int delay;
bool changed;
-} Settings;
+};
void Settings_delete(Settings* this);
diff --git a/configure.ac b/configure.ac
index a952d5ea..0edf493d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,9 @@ case "$target" in
;;
esac
+my_htop_platform=unsupported
+
+
# Checks for libraries.
# ----------------------------------------------------------------------
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index be4e627a..9c26018d 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, ProcessList* pl) {
+ LinuxProcess* this = calloc(sizeof(LinuxProcess), 1);
+ Process_init(&this->super, settings, pl);
+ 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 97ddf90b..ec2740e9 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 c2d3fa7c..2bce78e5 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -319,6 +319,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 {
@@ -464,7 +465,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
process = existingProcess;
assert(process->pid == pid);
} else {
- process = Process_new(this);
+ process = (Process*) LinuxProcess_new(settings, this);
assert(process->comm == NULL);
process->pid = pid;
process->tgid = parent ? parent->pid : pid;
@@ -568,7 +569,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
if (existingProcess)
ProcessList_remove(this, process);
else
- Process_delete((Object*)process);
+ LinuxProcess_delete((Object*)process);
}
}
closedir(dir);
diff --git a/linux/Platform.c b/linux/Platform.c
index ee5abf81..70a0f55c 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -27,6 +27,7 @@ in the source distribution for its full text.
/*{
#include "Action.h"
#include "BatteryMeter.h"
+#include "LinuxProcess.h"
}*/
static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
diff --git a/linux/Platform.h b/linux/Platform.h
index 2058419c..446c51d1 100644
--- a/linux/Platform.h
+++ b/linux/Platform.h
@@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "Action.h"
#include "BatteryMeter.h"
+#include "LinuxProcess.h"
void Platform_setBindings(Htop_Action* keys);
diff --git a/unsupported/Platform.c b/unsupported/Platform.c
index e5f22d2c..2178a373 100644
--- a/unsupported/Platform.c
+++ b/unsupported/Platform.c
@@ -60,3 +60,7 @@ int Platform_getMaxPid() {
return -1;
}
+void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) {
+ *level = -1;
+ *isOnAC = AC_ERROR;
+}
diff --git a/unsupported/Platform.h b/unsupported/Platform.h
index 888e8cf3..0a822e75 100644
--- a/unsupported/Platform.h
+++ b/unsupported/Platform.h
@@ -23,5 +23,6 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid();
+void Platform_getBatteryLevel(double* level, ACPresence* isOnAC);
#endif

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