mirror of https://github.com/xzeldon/htop.git
Fix allocation of processes. Closes #166.
Conflicts: Process.c Process.h ProcessList.c ScreenManager.c linux/LinuxProcessList.c
This commit is contained in:
parent
cce2202a1f
commit
9780c312f4
|
@ -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>
|
||||
|
|
11
Process.c
11
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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -60,3 +60,7 @@ int Platform_getMaxPid() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) {
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,6 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
|||
|
||||
int Platform_getMaxPid();
|
||||
|
||||
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue