EnvScreen.c 1.51 KB
Newer Older
1
2
#include "EnvScreen.h"

Michael Klein's avatar
Michael Klein committed
3
#include "config.h"
4
5
6
#include "CRT.h"
#include "IncSet.h"
#include "ListItem.h"
Michael Klein's avatar
Michael Klein committed
7
#include "Platform.h"
8
9
10
11
12
13
14
#include "StringUtils.h"

#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/*{
15
#include "InfoScreen.h"
16
17

typedef struct EnvScreen_ {
18
   InfoScreen super;
19
20
21
} EnvScreen;
}*/

22
23
24
25
26
27
28
29
InfoScreenClass EnvScreen_class = {
   .super = {
      .extends = Class(Object),
      .delete = EnvScreen_delete
   },
   .scan = EnvScreen_scan,
   .draw = EnvScreen_draw
};
30
31
32

EnvScreen* EnvScreen_new(Process* process) {
   EnvScreen* this = malloc(sizeof(EnvScreen));
33
34
   Object_setClass(this, Class(EnvScreen));
   return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ");
35
36
}

37
38
void EnvScreen_delete(Object* this) {
   free(InfoScreen_done((InfoScreen*)this));
39
40
}

41
42
void EnvScreen_draw(InfoScreen* this) {
   InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, this->process->comm);
43
44
}

45
void EnvScreen_scan(InfoScreen* this) {
46
47
48
49
50
   Panel* panel = this->display;
   int idx = MAX(Panel_getSelectedIndex(panel), 0);

   Panel_prune(panel);

51
52
53
54
55
56
   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)
57
         InfoScreen_addLine(this, p);
58
      free(env);
59
60
   }
   else {
61
      InfoScreen_addLine(this, "Could not read process environment.");
62
63
   }

64
   Vector_insertionSort(this->lines);
65
66
67
   Vector_insertionSort(panel->items);
   Panel_setSelected(panel, idx);
}