aboutsummaryrefslogtreecommitdiffstats
path: root/src/firemon
diff options
context:
space:
mode:
authorLibravatar startx2017 <vradu.startx@yandex.com>2017-04-29 08:51:18 -0400
committerLibravatar startx2017 <vradu.startx@yandex.com>2017-04-29 08:51:18 -0400
commit4b6169ca1ee2cd3138a2fa93f3409eda412da304 (patch)
tree9d030ba34a8900aceb6bcb6c801393345b2e8281 /src/firemon
parenttypo (diff)
downloadfirejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.tar.gz
firejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.tar.zst
firejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.zip
firemon --top speed-up and firecfg cleanup
Diffstat (limited to 'src/firemon')
-rw-r--r--src/firemon/top.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/firemon/top.c b/src/firemon/top.c
index 73661a07a..081f04eba 100644
--- a/src/firemon/top.c
+++ b/src/firemon/top.c
@@ -28,6 +28,21 @@ static unsigned pgs_rss = 0;
28static unsigned pgs_shared = 0; 28static unsigned pgs_shared = 0;
29static unsigned clocktick = 0; 29static unsigned clocktick = 0;
30static unsigned long long sysuptime = 0; 30static unsigned long long sysuptime = 0;
31static int pgsz = 0;
32static uid_t cached_uid = 0;
33static char *cached_user_name = NULL;
34
35static char *get_user_name(uid_t uid) {
36 if (cached_user_name == NULL) {
37 cached_uid = uid;
38 cached_user_name = pid_get_user_name(uid);
39 return strdup(cached_user_name);
40 }
41 else if (uid == cached_uid)
42 return strdup(cached_user_name);
43 else
44 return pid_get_user_name(uid);
45}
31 46
32static char *get_header(void) { 47static char *get_header(void) {
33 char *rv; 48 char *rv;
@@ -89,11 +104,13 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
89 else 104 else
90 ptrcmd = ""; 105 ptrcmd = "";
91 } 106 }
107 else if (strncmp(cmd, "/usr/bin/firejail", 17) == 0)
108 ptrcmd = cmd + 9;
92 else 109 else
93 ptrcmd = cmd; 110 ptrcmd = cmd;
94 111
95 // user 112 // user
96 char *user = pid_get_user_name(pids[index].uid); 113 char *user = get_user_name(pids[index].uid);
97 char *ptruser; 114 char *ptruser;
98 if (user) 115 if (user)
99 ptruser = user; 116 ptruser = user;
@@ -101,7 +118,8 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
101 ptruser = ""; 118 ptruser = "";
102 119
103 // memory 120 // memory
104 int pgsz = getpagesize(); 121 if (pgsz == 0)
122 pgsz = getpagesize();
105 char rss[10]; 123 char rss[10];
106 snprintf(rss, 10, "%u", pgs_rss * pgsz / 1024); 124 snprintf(rss, 10, "%u", pgs_rss * pgsz / 1024);
107 char shared[10]; 125 char shared[10];
@@ -249,7 +267,7 @@ void top(void) {
249 pid_store_cpu(i, 0, &utime, &stime); 267 pid_store_cpu(i, 0, &utime, &stime);
250 } 268 }
251 269
252 // wait 5 seconds 270 // wait 1 second
253 firemon_sleep(itv); 271 firemon_sleep(itv);
254 272
255 // grab screen size 273 // grab screen size