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 "ProcessList.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.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>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
typedef struct Settings_ Settings;
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 1
|
#define PROCESS_FLAG_IO 1
|
||||||
#define PROCESS_FLAG_IOPRIO 2
|
#define PROCESS_FLAG_IOPRIO 2
|
||||||
#define PROCESS_FLAG_OPENVZ 4
|
#define PROCESS_FLAG_OPENVZ 4
|
||||||
|
@ -643,14 +645,12 @@ static void Process_display(Object* cast, RichString* out) {
|
||||||
assert(out->chlen > 0);
|
assert(out->chlen > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_delete(Object* cast) {
|
void Process_done(Process* this) {
|
||||||
Process* this = (Process*) cast;
|
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
free(this->comm);
|
free(this->comm);
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
free(this->cgroup);
|
free(this->cgroup);
|
||||||
#endif
|
#endif
|
||||||
free(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectClass Process_class = {
|
ObjectClass Process_class = {
|
||||||
|
@ -660,9 +660,7 @@ ObjectClass Process_class = {
|
||||||
.compare = Process_compare
|
.compare = Process_compare
|
||||||
};
|
};
|
||||||
|
|
||||||
Process* Process_new(struct ProcessList_ *pl) {
|
void Process_init(Process* this, struct Settings_* settings, struct ProcessList_* pl) {
|
||||||
Process* this = calloc(1, sizeof(Process));
|
|
||||||
Object_setClass(this, Class(Process));
|
|
||||||
this->pid = 0;
|
this->pid = 0;
|
||||||
this->pl = pl;
|
this->pl = pl;
|
||||||
this->tag = false;
|
this->tag = false;
|
||||||
|
@ -678,7 +676,6 @@ Process* Process_new(struct ProcessList_ *pl) {
|
||||||
this->cgroup = NULL;
|
this->cgroup = NULL;
|
||||||
#endif
|
#endif
|
||||||
if (Process_getuid == -1) Process_getuid = getuid();
|
if (Process_getuid == -1) Process_getuid = getuid();
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_toggleTag(Process* this) {
|
void Process_toggleTag(Process* this) {
|
||||||
|
|
|
@ -24,6 +24,8 @@ in the source distribution for its full text.
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
typedef struct Settings_ Settings;
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 1
|
#define PROCESS_FLAG_IO 1
|
||||||
#define PROCESS_FLAG_IOPRIO 2
|
#define PROCESS_FLAG_IOPRIO 2
|
||||||
#define PROCESS_FLAG_OPENVZ 4
|
#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_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * 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;
|
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);
|
void Process_toggleTag(Process* this);
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,14 @@ in the source distribution for its full text.
|
||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct Settings_ {
|
struct Settings_ {
|
||||||
char* userSettings;
|
char* userSettings;
|
||||||
ProcessList* pl;
|
ProcessList* pl;
|
||||||
Header* header;
|
Header* header;
|
||||||
int colorScheme;
|
int colorScheme;
|
||||||
int delay;
|
int delay;
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
};
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,14 @@ in the source distribution for its full text.
|
||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct Settings_ {
|
struct Settings_ {
|
||||||
char* userSettings;
|
char* userSettings;
|
||||||
ProcessList* pl;
|
ProcessList* pl;
|
||||||
Header* header;
|
Header* header;
|
||||||
int colorScheme;
|
int colorScheme;
|
||||||
int delay;
|
int delay;
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
};
|
||||||
|
|
||||||
|
|
||||||
void Settings_delete(Settings* this);
|
void Settings_delete(Settings* this);
|
||||||
|
|
|
@ -33,6 +33,9 @@ case "$target" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
my_htop_platform=unsupported
|
||||||
|
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
|
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 "LinuxProcess.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
@ -22,8 +23,23 @@ typedef struct LinuxProcess_ {
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
} LinuxProcess;
|
} 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
|
[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
|
an io priority formally uses "none" as scheduling class, but the
|
||||||
|
|
|
@ -17,6 +17,12 @@ typedef struct LinuxProcess_ {
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
} LinuxProcess;
|
} 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
|
[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;
|
int nFields;
|
||||||
char** fields = String_split(trimmed, ':', &nFields);
|
char** fields = String_split(trimmed, ':', &nFields);
|
||||||
free(trimmed);
|
free(trimmed);
|
||||||
|
free(process->cgroup);
|
||||||
if (nFields >= 3) {
|
if (nFields >= 3) {
|
||||||
process->cgroup = strndup(fields[2] + 1, 10);
|
process->cgroup = strndup(fields[2] + 1, 10);
|
||||||
} else {
|
} else {
|
||||||
|
@ -464,7 +465,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
|
||||||
process = existingProcess;
|
process = existingProcess;
|
||||||
assert(process->pid == pid);
|
assert(process->pid == pid);
|
||||||
} else {
|
} else {
|
||||||
process = Process_new(this);
|
process = (Process*) LinuxProcess_new(settings, this);
|
||||||
assert(process->comm == NULL);
|
assert(process->comm == NULL);
|
||||||
process->pid = pid;
|
process->pid = pid;
|
||||||
process->tgid = parent ? parent->pid : pid;
|
process->tgid = parent ? parent->pid : pid;
|
||||||
|
@ -568,7 +569,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
|
||||||
if (existingProcess)
|
if (existingProcess)
|
||||||
ProcessList_remove(this, process);
|
ProcessList_remove(this, process);
|
||||||
else
|
else
|
||||||
Process_delete((Object*)process);
|
LinuxProcess_delete((Object*)process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
|
@ -27,6 +27,7 @@ in the source distribution for its full text.
|
||||||
/*{
|
/*{
|
||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
|
#include "LinuxProcess.h"
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
|
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 "Action.h"
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
|
#include "LinuxProcess.h"
|
||||||
|
|
||||||
void Platform_setBindings(Htop_Action* keys);
|
void Platform_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
|
|
|
@ -60,3 +60,7 @@ int Platform_getMaxPid() {
|
||||||
return -1;
|
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();
|
int Platform_getMaxPid();
|
||||||
|
|
||||||
|
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue