diff options
author | startx2017 <vradu.startx@yandex.com> | 2017-04-29 08:51:18 -0400 |
---|---|---|
committer | startx2017 <vradu.startx@yandex.com> | 2017-04-29 08:51:18 -0400 |
commit | 4b6169ca1ee2cd3138a2fa93f3409eda412da304 (patch) | |
tree | 9d030ba34a8900aceb6bcb6c801393345b2e8281 /src | |
parent | typo (diff) | |
download | firejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.tar.gz firejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.tar.zst firejail-4b6169ca1ee2cd3138a2fa93f3409eda412da304.zip |
firemon --top speed-up and firecfg cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/firecfg/main.c | 5 | ||||
-rw-r--r-- | src/firemon/top.c | 24 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c index 7d63cb848..c8af9d03a 100644 --- a/src/firecfg/main.c +++ b/src/firecfg/main.c | |||
@@ -218,10 +218,7 @@ static void set_file(const char *name, const char *firejail_exec) { | |||
218 | errExit("asprintf"); | 218 | errExit("asprintf"); |
219 | 219 | ||
220 | struct stat s; | 220 | struct stat s; |
221 | if (stat(fname, &s) == 0) { | 221 | if (stat(fname, &s) != 0) { |
222 | printf(" %s is already present, skipping...\n", name); | ||
223 | } | ||
224 | else { | ||
225 | int rv = symlink(firejail_exec, fname); | 222 | int rv = symlink(firejail_exec, fname); |
226 | if (rv) { | 223 | if (rv) { |
227 | fprintf(stderr, "Error: cannot create %s symbolic link\n", fname); | 224 | fprintf(stderr, "Error: cannot create %s symbolic link\n", fname); |
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; | |||
28 | static unsigned pgs_shared = 0; | 28 | static unsigned pgs_shared = 0; |
29 | static unsigned clocktick = 0; | 29 | static unsigned clocktick = 0; |
30 | static unsigned long long sysuptime = 0; | 30 | static unsigned long long sysuptime = 0; |
31 | static int pgsz = 0; | ||
32 | static uid_t cached_uid = 0; | ||
33 | static char *cached_user_name = NULL; | ||
34 | |||
35 | static 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 | ||
32 | static char *get_header(void) { | 47 | static 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 |