diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2015-02-20 14:52:10 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-02-23 01:13:40 -0300 |
commit | 9780c312f40633a2ce23300cc76faf64e07a87ed (patch) | |
tree | 1d04f7070e5183f6f9aad77c91d4d81025868a24 | |
parent | cce2202a1ffdce2d6d775e3d0d5ced092d823598 (diff) |
Fix allocation of processes. Closes #166.
Conflicts:
Process.c
Process.h
ProcessList.c
ScreenManager.c
linux/LinuxProcessList.c
-rw-r--r-- | BatteryMeter.c | 1 | ||||
-rw-r--r-- | Process.c | 11 | ||||
-rw-r--r-- | Process.h | 6 | ||||
-rw-r--r-- | Settings.c | 4 | ||||
-rw-r--r-- | Settings.h | 4 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | linux/LinuxProcess.c | 16 | ||||
-rw-r--r-- | linux/LinuxProcess.h | 6 | ||||
-rw-r--r-- | linux/LinuxProcessList.c | 5 | ||||
-rw-r--r-- | linux/Platform.c | 1 | ||||
-rw-r--r-- | linux/Platform.h | 1 | ||||
-rw-r--r-- | unsupported/Platform.c | 4 | ||||
-rw-r--r-- | unsupported/Platform.h | 1 |
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> @@ -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) { @@ -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); @@ -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; +}; }*/ @@ -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 |