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"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2015-12-02 21:58:22 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const InfoScreenClass EnvScreen_class = {
|
2016-01-12 08:00:58 +00:00
|
|
|
.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) {
|
2016-02-02 14:53:02 +00:00
|
|
|
EnvScreen* this = xMalloc(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;
|
2020-09-09 06:56:04 +00:00
|
|
|
int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0);
|
2015-12-02 21:58:22 +00:00
|
|
|
|
|
|
|
Panel_prune(panel);
|
|
|
|
|
2017-07-26 18:40:55 +00:00
|
|
|
CRT_dropPrivileges();
|
|
|
|
char* env = Platform_getProcessEnv(this->process->pid);
|
|
|
|
CRT_restorePrivileges();
|
2016-01-06 21:52:37 +00:00
|
|
|
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);
|
|
|
|
}
|