2020-09-19 11:55:23 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2015-12-02 21:58:22 +00:00
|
|
|
#include "EnvScreen.h"
|
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-12-02 21:58:22 +00:00
|
|
|
#include "CRT.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Macros.h"
|
|
|
|
#include "Panel.h"
|
2015-12-03 21:16:10 +00:00
|
|
|
#include "Platform.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "ProvideCurses.h"
|
|
|
|
#include "Vector.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
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));
|
2020-10-31 22:28:02 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-21 20:34:23 +00:00
|
|
|
static void EnvScreen_draw(InfoScreen* this) {
|
2020-10-17 10:54:45 +00:00
|
|
|
InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, Process_getCommand(this->process));
|
2015-12-02 21:58:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 20:34:23 +00:00
|
|
|
static 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) {
|
2020-10-31 22:28:02 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-12-21 20:34:23 +00:00
|
|
|
|
|
|
|
const InfoScreenClass EnvScreen_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Object),
|
|
|
|
.delete = EnvScreen_delete
|
|
|
|
},
|
|
|
|
.scan = EnvScreen_scan,
|
|
|
|
.draw = EnvScreen_draw
|
|
|
|
};
|