2020-09-19 13:55:23 +02:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2015-12-02 22:58:22 +01:00
|
|
|
#include "EnvScreen.h"
|
|
|
|
|
2020-09-19 13:55:23 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-12-02 22:58:22 +01:00
|
|
|
#include "CRT.h"
|
2020-09-19 13:55:23 +02:00
|
|
|
#include "Macros.h"
|
|
|
|
#include "Panel.h"
|
2015-12-03 22:16:10 +01:00
|
|
|
#include "Platform.h"
|
2020-09-19 13:55:23 +02:00
|
|
|
#include "ProvideCurses.h"
|
|
|
|
#include "Vector.h"
|
2020-10-14 20:21:09 +02:00
|
|
|
#include "XUtils.h"
|
2015-12-02 22:58:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
EnvScreen* EnvScreen_new(Process* process) {
|
2016-02-02 15:53:02 +01:00
|
|
|
EnvScreen* this = xMalloc(sizeof(EnvScreen));
|
2016-01-12 06:00:58 -02:00
|
|
|
Object_setClass(this, Class(EnvScreen));
|
2021-01-11 12:53:07 +01:00
|
|
|
return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " ");
|
2015-12-02 22:58:22 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 06:00:58 -02:00
|
|
|
void EnvScreen_delete(Object* this) {
|
|
|
|
free(InfoScreen_done((InfoScreen*)this));
|
2015-12-02 22:58:22 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 21:34:23 +01:00
|
|
|
static void EnvScreen_draw(InfoScreen* this) {
|
2020-10-17 16:24:45 +05:30
|
|
|
InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, Process_getCommand(this->process));
|
2015-12-02 22:58:22 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 21:34:23 +01:00
|
|
|
static void EnvScreen_scan(InfoScreen* this) {
|
2015-12-02 22:58:22 +01:00
|
|
|
Panel* panel = this->display;
|
2020-09-09 16:56:04 +10:00
|
|
|
int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0);
|
2015-12-02 22:58:22 +01:00
|
|
|
|
|
|
|
Panel_prune(panel);
|
|
|
|
|
2017-07-26 15:40:55 -03:00
|
|
|
CRT_dropPrivileges();
|
|
|
|
char* env = Platform_getProcessEnv(this->process->pid);
|
|
|
|
CRT_restorePrivileges();
|
2016-01-06 22:52:37 +01:00
|
|
|
if (env) {
|
2020-10-31 23:28:02 +01:00
|
|
|
for (char* p = env; *p; p = strrchr(p, 0) + 1)
|
2016-01-12 06:00:58 -02:00
|
|
|
InfoScreen_addLine(this, p);
|
2016-01-06 22:52:37 +01:00
|
|
|
free(env);
|
2015-12-02 22:58:22 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-01-12 06:00:58 -02:00
|
|
|
InfoScreen_addLine(this, "Could not read process environment.");
|
2015-12-02 22:58:22 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 06:00:58 -02:00
|
|
|
Vector_insertionSort(this->lines);
|
2015-12-02 22:58:22 +01:00
|
|
|
Vector_insertionSort(panel->items);
|
|
|
|
Panel_setSelected(panel, idx);
|
|
|
|
}
|
2020-12-21 21:34:23 +01:00
|
|
|
|
|
|
|
const InfoScreenClass EnvScreen_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Object),
|
|
|
|
.delete = EnvScreen_delete
|
|
|
|
},
|
|
|
|
.scan = EnvScreen_scan,
|
|
|
|
.draw = EnvScreen_draw
|
|
|
|
};
|