2015-12-02 21:58:22 +00:00
|
|
|
#include "EnvScreen.h"
|
|
|
|
|
2015-12-03 21:16:10 +00:00
|
|
|
#include "config.h"
|
2015-12-02 21:58:22 +00:00
|
|
|
#include "CRT.h"
|
|
|
|
#include "IncSet.h"
|
|
|
|
#include "ListItem.h"
|
2015-12-03 21:16:10 +00:00
|
|
|
#include "Platform.h"
|
2015-12-02 21:58:22 +00:00
|
|
|
#include "StringUtils.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/*{
|
2016-01-12 08:00:58 +00:00
|
|
|
#include "InfoScreen.h"
|
2015-12-02 21:58:22 +00:00
|
|
|
|
|
|
|
typedef struct EnvScreen_ {
|
2016-01-12 08:00:58 +00:00
|
|
|
InfoScreen super;
|
2015-12-02 21:58:22 +00:00
|
|
|
} EnvScreen;
|
|
|
|
}*/
|
|
|
|
|
2016-01-12 08:00:58 +00:00
|
|
|
InfoScreenClass EnvScreen_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Object),
|
|
|
|
.delete = EnvScreen_delete
|
|
|
|
},
|
|
|
|
.scan = EnvScreen_scan,
|
|
|
|
.draw = EnvScreen_draw
|
|
|
|
};
|
2015-12-02 21:58:22 +00:00
|
|
|
|
|
|
|
EnvScreen* EnvScreen_new(Process* process) {
|
|
|
|
EnvScreen* this = malloc(sizeof(EnvScreen));
|
2016-01-12 08:00:58 +00:00
|
|
|
Object_setClass(this, Class(EnvScreen));
|
|
|
|
return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ");
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:00:58 +00:00
|
|
|
void EnvScreen_delete(Object* this) {
|
|
|
|
free(InfoScreen_done((InfoScreen*)this));
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:00:58 +00:00
|
|
|
void EnvScreen_draw(InfoScreen* this) {
|
|
|
|
InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, this->process->comm);
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:00:58 +00:00
|
|
|
void EnvScreen_scan(InfoScreen* this) {
|
2015-12-02 21:58:22 +00:00
|
|
|
Panel* panel = this->display;
|
|
|
|
int idx = MAX(Panel_getSelectedIndex(panel), 0);
|
|
|
|
|
|
|
|
Panel_prune(panel);
|
|
|
|
|
2016-01-06 21:52:37 +00:00
|
|
|
uid_t euid = geteuid();
|
|
|
|
seteuid(getuid());
|
|
|
|
char *env = Platform_getProcessEnv(this->process->pid);
|
|
|
|
seteuid(euid);
|
|
|
|
if (env) {
|
|
|
|
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
2016-01-12 08:00:58 +00:00
|
|
|
InfoScreen_addLine(this, p);
|
2016-01-06 21:52:37 +00:00
|
|
|
free(env);
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-01-12 08:00:58 +00:00
|
|
|
InfoScreen_addLine(this, "Could not read process environment.");
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:00:58 +00:00
|
|
|
Vector_insertionSort(this->lines);
|
2015-12-02 21:58:22 +00:00
|
|
|
Vector_insertionSort(panel->items);
|
|
|
|
Panel_setSelected(panel, idx);
|
|
|
|
}
|