diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:01:07 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:01:07 +0200 |
commit | ff9409b1737627857eb47f64f536a3f66b6a09a4 (patch) | |
tree | 61b631ba551e68a4f656b8b76ff7bd0d9955fc64 /EnvScreen.c | |
parent | f75ab6d2c11e8a8e18191b087564aedebbeb96c5 (diff) | |
download | debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.tar.gz debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.tar.bz2 debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.zip |
Imported Upstream version 2.0.0upstream/2.0.0
Diffstat (limited to 'EnvScreen.c')
-rw-r--r-- | EnvScreen.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/EnvScreen.c b/EnvScreen.c new file mode 100644 index 0000000..4414c39 --- /dev/null +++ b/EnvScreen.c @@ -0,0 +1,67 @@ +#include "EnvScreen.h" + +#include "config.h" +#include "CRT.h" +#include "IncSet.h" +#include "ListItem.h" +#include "Platform.h" +#include "StringUtils.h" + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/*{ +#include "InfoScreen.h" + +typedef struct EnvScreen_ { + InfoScreen super; +} EnvScreen; +}*/ + +InfoScreenClass EnvScreen_class = { + .super = { + .extends = Class(Object), + .delete = EnvScreen_delete + }, + .scan = EnvScreen_scan, + .draw = EnvScreen_draw +}; + +EnvScreen* EnvScreen_new(Process* process) { + EnvScreen* this = xMalloc(sizeof(EnvScreen)); + Object_setClass(this, Class(EnvScreen)); + return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " "); +} + +void EnvScreen_delete(Object* this) { + free(InfoScreen_done((InfoScreen*)this)); +} + +void EnvScreen_draw(InfoScreen* this) { + InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, this->process->comm); +} + +void EnvScreen_scan(InfoScreen* this) { + Panel* panel = this->display; + int idx = MAX(Panel_getSelectedIndex(panel), 0); + + Panel_prune(panel); + + 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) + InfoScreen_addLine(this, p); + free(env); + } + else { + InfoScreen_addLine(this, "Could not read process environment."); + } + + Vector_insertionSort(this->lines); + Vector_insertionSort(panel->items); + Panel_setSelected(panel, idx); +} |