aboutsummaryrefslogtreecommitdiffstats
path: root/src/firemon
diff options
context:
space:
mode:
authorLibravatar Fred Barclay <Fred-Barclay@users.noreply.github.com>2017-05-24 14:13:52 -0500
committerLibravatar Fred Barclay <Fred-Barclay@users.noreply.github.com>2017-05-24 14:13:52 -0500
commit96c920e166b40bbe50f216e294f2efac154a1cb2 (patch)
treefa80a34e81863ab897f2f2b8ec4124b10d023516 /src/firemon
parentremove trailing whitespace from etc/ (diff)
downloadfirejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.gz
firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.zst
firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.zip
Remove trailing whitespace from src/
Diffstat (limited to 'src/firemon')
-rw-r--r--src/firemon/Makefile.in3
-rw-r--r--src/firemon/arp.c10
-rw-r--r--src/firemon/caps.c7
-rw-r--r--src/firemon/cgroup.c7
-rw-r--r--src/firemon/cpu.c7
-rw-r--r--src/firemon/firemon.c30
-rw-r--r--src/firemon/interface.c13
-rw-r--r--src/firemon/list.c3
-rw-r--r--src/firemon/netstats.c35
-rw-r--r--src/firemon/procevent.c60
-rw-r--r--src/firemon/route.c26
-rw-r--r--src/firemon/seccomp.c7
-rw-r--r--src/firemon/top.c55
-rw-r--r--src/firemon/tree.c3
-rw-r--r--src/firemon/x11.c7
15 files changed, 129 insertions, 144 deletions
diff --git a/src/firemon/Makefile.in b/src/firemon/Makefile.in
index efc48b212..a7a97cf5a 100644
--- a/src/firemon/Makefile.in
+++ b/src/firemon/Makefile.in
@@ -12,7 +12,7 @@ C_FILE_LIST = $(sort $(wildcard *.c))
12OBJS = $(C_FILE_LIST:.c=.o) 12OBJS = $(C_FILE_LIST:.c=.o)
13BINOBJS = $(foreach file, $(OBJS), $file) 13BINOBJS = $(foreach file, $(OBJS), $file)
14CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIE -pie -Wformat -Wformat-security 14CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIE -pie -Wformat -Wformat-security
15LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now 15LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now
16HAVE_GCOV=@HAVE_GCOV@ 16HAVE_GCOV=@HAVE_GCOV@
17EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@ 17EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@
18 18
@@ -27,4 +27,3 @@ clean:; rm -f *.o firemon *.gcov *.gcda *.gcno
27 27
28distclean: clean 28distclean: clean
29 rm -fr Makefile 29 rm -fr Makefile
30
diff --git a/src/firemon/arp.c b/src/firemon/arp.c
index d30983e4a..51a699273 100644
--- a/src/firemon/arp.c
+++ b/src/firemon/arp.c
@@ -24,7 +24,7 @@ static void print_arp(const char *fname) {
24 FILE *fp = fopen(fname, "r"); 24 FILE *fp = fopen(fname, "r");
25 if (!fp) 25 if (!fp)
26 return; 26 return;
27 27
28 printf(" ARP Table:\n"); 28 printf(" ARP Table:\n");
29 char buf[MAXBUF]; 29 char buf[MAXBUF];
30 while (fgets(buf, MAXBUF, fp)) { 30 while (fgets(buf, MAXBUF, fp)) {
@@ -54,7 +54,7 @@ static void print_arp(const char *fname) {
54 int rv = sscanf(start, "%s %s %s %s %s %s\n", ip, type, flags, mac, mask, device); 54 int rv = sscanf(start, "%s %s %s %s %s %s\n", ip, type, flags, mac, mask, device);
55 if (rv != 6) 55 if (rv != 6)
56 continue; 56 continue;
57 57
58 // destination ip 58 // destination ip
59 unsigned a, b, c, d; 59 unsigned a, b, c, d;
60 if (sscanf(ip, "%u.%u.%u.%u", &a, &b, &c, &d) != 4 || a > 255 || b > 255 || c > 255 || d > 255) 60 if (sscanf(ip, "%u.%u.%u.%u", &a, &b, &c, &d) != 4 || a > 255 || b > 255 || c > 255 || d > 255)
@@ -67,14 +67,14 @@ static void print_arp(const char *fname) {
67 printf(" %d.%d.%d.%d dev %s lladdr %s REACHABLE\n", 67 printf(" %d.%d.%d.%d dev %s lladdr %s REACHABLE\n",
68 PRINT_IP(destip), device, mac); 68 PRINT_IP(destip), device, mac);
69 } 69 }
70 70
71 fclose(fp); 71 fclose(fp);
72 72
73} 73}
74 74
75void arp(pid_t pid, int print_procs) { 75void arp(pid_t pid, int print_procs) {
76 pid_read(pid); 76 pid_read(pid);
77 77
78 // print processes 78 // print processes
79 int i; 79 int i;
80 for (i = 0; i < max_pids; i++) { 80 for (i = 0; i < max_pids; i++) {
@@ -93,5 +93,3 @@ void arp(pid_t pid, int print_procs) {
93 } 93 }
94 printf("\n"); 94 printf("\n");
95} 95}
96
97
diff --git a/src/firemon/caps.c b/src/firemon/caps.c
index a13b784a2..4a18833d0 100644
--- a/src/firemon/caps.c
+++ b/src/firemon/caps.c
@@ -32,7 +32,7 @@ static void print_caps(int pid) {
32 free(file); 32 free(file);
33 return; 33 return;
34 } 34 }
35 35
36 char buf[MAXBUF]; 36 char buf[MAXBUF];
37 while (fgets(buf, MAXBUF, fp)) { 37 while (fgets(buf, MAXBUF, fp)) {
38 if (strncmp(buf, "CapBnd:", 7) == 0) { 38 if (strncmp(buf, "CapBnd:", 7) == 0) {
@@ -44,10 +44,10 @@ static void print_caps(int pid) {
44 fclose(fp); 44 fclose(fp);
45 free(file); 45 free(file);
46} 46}
47 47
48void caps(pid_t pid, int print_procs) { 48void caps(pid_t pid, int print_procs) {
49 pid_read(pid); // include all processes 49 pid_read(pid); // include all processes
50 50
51 // print processes 51 // print processes
52 int i; 52 int i;
53 for (i = 0; i < max_pids; i++) { 53 for (i = 0; i < max_pids; i++) {
@@ -61,4 +61,3 @@ void caps(pid_t pid, int print_procs) {
61 } 61 }
62 printf("\n"); 62 printf("\n");
63} 63}
64
diff --git a/src/firemon/cgroup.c b/src/firemon/cgroup.c
index 48427210b..41afa41fd 100644
--- a/src/firemon/cgroup.c
+++ b/src/firemon/cgroup.c
@@ -33,7 +33,7 @@ static void print_cgroup(int pid) {
33 free(file); 33 free(file);
34 return; 34 return;
35 } 35 }
36 36
37 char buf[MAXBUF]; 37 char buf[MAXBUF];
38 if (fgets(buf, MAXBUF, fp)) { 38 if (fgets(buf, MAXBUF, fp)) {
39 printf(" %s", buf); 39 printf(" %s", buf);
@@ -43,10 +43,10 @@ static void print_cgroup(int pid) {
43 fclose(fp); 43 fclose(fp);
44 free(file); 44 free(file);
45} 45}
46 46
47void cgroup(pid_t pid, int print_procs) { 47void cgroup(pid_t pid, int print_procs) {
48 pid_read(pid); 48 pid_read(pid);
49 49
50 // print processes 50 // print processes
51 int i; 51 int i;
52 for (i = 0; i < max_pids; i++) { 52 for (i = 0; i < max_pids; i++) {
@@ -60,4 +60,3 @@ void cgroup(pid_t pid, int print_procs) {
60 } 60 }
61 printf("\n"); 61 printf("\n");
62} 62}
63
diff --git a/src/firemon/cpu.c b/src/firemon/cpu.c
index 2a6979573..7d31cd44d 100644
--- a/src/firemon/cpu.c
+++ b/src/firemon/cpu.c
@@ -33,7 +33,7 @@ static void print_cpu(int pid) {
33 free(file); 33 free(file);
34 return; 34 return;
35 } 35 }
36 36
37 char buf[MAXBUF]; 37 char buf[MAXBUF];
38 while (fgets(buf, MAXBUF, fp)) { 38 while (fgets(buf, MAXBUF, fp)) {
39 if (strncmp(buf, "Cpus_allowed_list:", 18) == 0) { 39 if (strncmp(buf, "Cpus_allowed_list:", 18) == 0) {
@@ -45,10 +45,10 @@ static void print_cpu(int pid) {
45 fclose(fp); 45 fclose(fp);
46 free(file); 46 free(file);
47} 47}
48 48
49void cpu(pid_t pid, int print_procs) { 49void cpu(pid_t pid, int print_procs) {
50 pid_read(pid); 50 pid_read(pid);
51 51
52 // print processes 52 // print processes
53 int i; 53 int i;
54 for (i = 0; i < max_pids; i++) { 54 for (i = 0; i < max_pids; i++) {
@@ -62,4 +62,3 @@ void cpu(pid_t pid, int print_procs) {
62 } 62 }
63 printf("\n"); 63 printf("\n");
64} 64}
65
diff --git a/src/firemon/firemon.c b/src/firemon/firemon.c
index da5cc2d97..aaeffdbd2 100644
--- a/src/firemon/firemon.c
+++ b/src/firemon/firemon.c
@@ -24,7 +24,7 @@
24#include <sys/prctl.h> 24#include <sys/prctl.h>
25#include <grp.h> 25#include <grp.h>
26#include <sys/stat.h> 26#include <sys/stat.h>
27 27
28static int arg_route = 0; 28static int arg_route = 0;
29static int arg_arp = 0; 29static int arg_arp = 0;
30static int arg_tree = 0; 30static int arg_tree = 0;
@@ -49,7 +49,7 @@ static void my_handler(int s){
49 49
50 if (terminal_set) 50 if (terminal_set)
51 tcsetattr(0, TCSANOW, &tlocal); 51 tcsetattr(0, TCSANOW, &tlocal);
52 exit(0); 52 exit(0);
53} 53}
54 54
55// find the first child process for the specified pid 55// find the first child process for the specified pid
@@ -60,7 +60,7 @@ int find_child(int id) {
60 if (pids[i].level == 2 && pids[i].parent == id) 60 if (pids[i].level == 2 && pids[i].parent == id)
61 return i; 61 return i;
62 } 62 }
63 63
64 return -1; 64 return -1;
65} 65}
66 66
@@ -118,7 +118,7 @@ int main(int argc, char **argv) {
118 printf("firemon version %s\n\n", VERSION); 118 printf("firemon version %s\n\n", VERSION);
119 return 0; 119 return 0;
120 } 120 }
121 121
122 // options without a pid argument 122 // options without a pid argument
123 else if (strcmp(argv[i], "--top") == 0) 123 else if (strcmp(argv[i], "--top") == 0)
124 arg_top = 1; 124 arg_top = 1;
@@ -131,7 +131,7 @@ int main(int argc, char **argv) {
131 if (getuid() != 0 && stat("/proc/sys/kernel/grsecurity", &s) == 0) { 131 if (getuid() != 0 && stat("/proc/sys/kernel/grsecurity", &s) == 0) {
132 fprintf(stderr, "Error: this feature is not available on Grsecurity systems\n"); 132 fprintf(stderr, "Error: this feature is not available on Grsecurity systems\n");
133 exit(1); 133 exit(1);
134 } 134 }
135 arg_netstats = 1; 135 arg_netstats = 1;
136 } 136 }
137 137
@@ -166,17 +166,17 @@ int main(int argc, char **argv) {
166 return 1; 166 return 1;
167 } 167 }
168 } 168 }
169 169
170 // etc 170 // etc
171 else if (strcmp(argv[i], "--nowrap") == 0) 171 else if (strcmp(argv[i], "--nowrap") == 0)
172 arg_nowrap = 1; 172 arg_nowrap = 1;
173 173
174 // invalid option 174 // invalid option
175 else if (*argv[i] == '-') { 175 else if (*argv[i] == '-') {
176 fprintf(stderr, "Error: invalid option\n"); 176 fprintf(stderr, "Error: invalid option\n");
177 return 1; 177 return 1;
178 } 178 }
179 179
180 // PID argument 180 // PID argument
181 else { 181 else {
182 // this should be a pid number 182 // this should be a pid number
@@ -199,9 +199,9 @@ int main(int argc, char **argv) {
199 fprintf(stderr, "Error: /proc is mounted hidepid, you would need to be root to run this command\n"); 199 fprintf(stderr, "Error: /proc is mounted hidepid, you would need to be root to run this command\n");
200 exit(1); 200 exit(1);
201 } 201 }
202 202
203 if (arg_top) { 203 if (arg_top) {
204 top(); 204 top();
205 return 0; 205 return 0;
206 } 206 }
207 if (arg_list) { 207 if (arg_list) {
@@ -210,9 +210,9 @@ int main(int argc, char **argv) {
210 } 210 }
211 if (arg_netstats) { 211 if (arg_netstats) {
212 netstats(); 212 netstats();
213 return 0; 213 return 0;
214 } 214 }
215 215
216 // cumulative options 216 // cumulative options
217 int print_procs = 1; 217 int print_procs = 1;
218 if (arg_tree) { 218 if (arg_tree) {
@@ -251,9 +251,9 @@ int main(int argc, char **argv) {
251 arp((pid_t) pid, print_procs); 251 arp((pid_t) pid, print_procs);
252 print_procs = 0; 252 print_procs = 0;
253 } 253 }
254 254
255 if (print_procs) 255 if (print_procs)
256 procevent((pid_t) pid); 256 procevent((pid_t) pid);
257 257
258 return 0; 258 return 0;
259} 259}
diff --git a/src/firemon/interface.c b/src/firemon/interface.c
index 77dd1f277..44374ed60 100644
--- a/src/firemon/interface.c
+++ b/src/firemon/interface.c
@@ -64,13 +64,13 @@ static void net_ifprint(void) {
64 memset(&ifr, 0, sizeof(ifr)); 64 memset(&ifr, 0, sizeof(ifr));
65 strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ); 65 strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ);
66 int rv = ioctl (fd, SIOCGIFHWADDR, &ifr); 66 int rv = ioctl (fd, SIOCGIFHWADDR, &ifr);
67 67
68 if (rv == 0) 68 if (rv == 0)
69 printf(" %s UP, %02x:%02x:%02x:%02x:%02x:%02x\n", 69 printf(" %s UP, %02x:%02x:%02x:%02x:%02x:%02x\n",
70 ifa->ifa_name, PRINT_MAC((unsigned char *) &ifr.ifr_hwaddr.sa_data)); 70 ifa->ifa_name, PRINT_MAC((unsigned char *) &ifr.ifr_hwaddr.sa_data));
71 else 71 else
72 printf(" %s UP\n", ifa->ifa_name); 72 printf(" %s UP\n", ifa->ifa_name);
73 73
74 printf(" tx/rx: %u/%u packets, %u/%u bytes\n", 74 printf(" tx/rx: %u/%u packets, %u/%u bytes\n",
75 stats->tx_packets, stats->rx_packets, 75 stats->tx_packets, stats->rx_packets,
76 stats->tx_bytes, stats->rx_bytes); 76 stats->tx_bytes, stats->rx_bytes);
@@ -78,7 +78,7 @@ static void net_ifprint(void) {
78 } 78 }
79 else 79 else
80 printf(" %s DOWN\n", ifa->ifa_name); 80 printf(" %s DOWN\n", ifa->ifa_name);
81 } 81 }
82 } 82 }
83 83
84 84
@@ -139,7 +139,7 @@ static void print_sandbox(pid_t pid) {
139 pid_t child = fork(); 139 pid_t child = fork();
140 if (child == -1) 140 if (child == -1)
141 return; 141 return;
142 142
143 if (child == 0) { 143 if (child == 0) {
144 int rv = join_namespace(pid, "net"); 144 int rv = join_namespace(pid, "net");
145 if (rv) 145 if (rv)
@@ -150,14 +150,14 @@ static void print_sandbox(pid_t pid) {
150#endif 150#endif
151 _exit(0); 151 _exit(0);
152 } 152 }
153 153
154 // wait for the child to finish 154 // wait for the child to finish
155 waitpid(child, NULL, 0); 155 waitpid(child, NULL, 0);
156} 156}
157 157
158void interface(pid_t pid, int print_procs) { 158void interface(pid_t pid, int print_procs) {
159 pid_read(pid); // a pid of 0 will include all processes 159 pid_read(pid); // a pid of 0 will include all processes
160 160
161 // print processes 161 // print processes
162 int i; 162 int i;
163 for (i = 0; i < max_pids; i++) { 163 for (i = 0; i < max_pids; i++) {
@@ -172,4 +172,3 @@ void interface(pid_t pid, int print_procs) {
172 } 172 }
173 printf("\n"); 173 printf("\n");
174} 174}
175
diff --git a/src/firemon/list.c b/src/firemon/list.c
index 2152df31f..708b66ae4 100644
--- a/src/firemon/list.c
+++ b/src/firemon/list.c
@@ -21,7 +21,7 @@
21 21
22void list(void) { 22void list(void) {
23 pid_read(0); // include all processes 23 pid_read(0); // include all processes
24 24
25 // print processes 25 // print processes
26 int i; 26 int i;
27 for (i = 0; i < max_pids; i++) { 27 for (i = 0; i < max_pids; i++) {
@@ -29,4 +29,3 @@ void list(void) {
29 pid_print_list(i, arg_nowrap); 29 pid_print_list(i, arg_nowrap);
30 } 30 }
31} 31}
32
diff --git a/src/firemon/netstats.c b/src/firemon/netstats.c
index 8d78b094b..c5e8a242c 100644
--- a/src/firemon/netstats.c
+++ b/src/firemon/netstats.c
@@ -35,7 +35,7 @@ static char *get_header(void) {
35 if (asprintf(&rv, "%-5.5s %-9.9s %-10.10s %-10.10s %s", 35 if (asprintf(&rv, "%-5.5s %-9.9s %-10.10s %-10.10s %s",
36 "PID", "User", "RX(KB/s)", "TX(KB/s)", "Command") == -1) 36 "PID", "User", "RX(KB/s)", "TX(KB/s)", "Command") == -1)
37 errExit("asprintf"); 37 errExit("asprintf");
38 38
39 return rv; 39 return rv;
40} 40}
41 41
@@ -59,7 +59,7 @@ void get_stats(int parent) {
59 free(fname); 59 free(fname);
60 goto errexit; 60 goto errexit;
61 } 61 }
62 62
63 char buf[MAXBUF]; 63 char buf[MAXBUF];
64 long long unsigned rx = 0; 64 long long unsigned rx = 0;
65 long long unsigned tx = 0; 65 long long unsigned tx = 0;
@@ -68,19 +68,19 @@ void get_stats(int parent) {
68 continue; 68 continue;
69 if (strncmp(buf, " face", 5) == 0) 69 if (strncmp(buf, " face", 5) == 0)
70 continue; 70 continue;
71 71
72 char *ptr = buf; 72 char *ptr = buf;
73 while (*ptr != '\0' && *ptr != ':') { 73 while (*ptr != '\0' && *ptr != ':') {
74 ptr++; 74 ptr++;
75 } 75 }
76 76
77 if (*ptr == '\0') { 77 if (*ptr == '\0') {
78 fclose(fp); 78 fclose(fp);
79 free(fname); 79 free(fname);
80 goto errexit; 80 goto errexit;
81 } 81 }
82 ptr++; 82 ptr++;
83 83
84 long long unsigned rxval; 84 long long unsigned rxval;
85 long long unsigned txval; 85 long long unsigned txval;
86 unsigned a, b, c, d, e, f, g; 86 unsigned a, b, c, d, e, f, g;
@@ -101,7 +101,7 @@ void get_stats(int parent) {
101 fclose(fp); 101 fclose(fp);
102 return; 102 return;
103 103
104errexit: 104errexit:
105 pids[parent].rx = 0; 105 pids[parent].rx = 0;
106 pids[parent].tx = 0; 106 pids[parent].tx = 0;
107 pids[parent].rx_delta = 0; 107 pids[parent].rx_delta = 0;
@@ -121,7 +121,7 @@ static void print_proc(int index, int itv, int col) {
121 } 121 }
122 else 122 else
123 ptrcmd = cmd; 123 ptrcmd = cmd;
124 124
125 // check network namespace 125 // check network namespace
126 char *name; 126 char *name;
127 if (asprintf(&name, "/run/firejail/network/%d-netmap", index) == -1) 127 if (asprintf(&name, "/run/firejail/network/%d-netmap", index) == -1)
@@ -145,35 +145,35 @@ static void print_proc(int index, int itv, int col) {
145 ptruser = user; 145 ptruser = user;
146 else 146 else
147 ptruser = ""; 147 ptruser = "";
148 148
149 149
150 float rx_kbps = ((float) pids[index].rx_delta / 1000) / itv; 150 float rx_kbps = ((float) pids[index].rx_delta / 1000) / itv;
151 char ptrrx[15]; 151 char ptrrx[15];
152 sprintf(ptrrx, "%.03f", rx_kbps); 152 sprintf(ptrrx, "%.03f", rx_kbps);
153 153
154 float tx_kbps = ((float) pids[index].tx_delta / 1000) / itv; 154 float tx_kbps = ((float) pids[index].tx_delta / 1000) / itv;
155 char ptrtx[15]; 155 char ptrtx[15];
156 sprintf(ptrtx, "%.03f", tx_kbps); 156 sprintf(ptrtx, "%.03f", tx_kbps);
157 157
158 char buf[1024 + 1]; 158 char buf[1024 + 1];
159 snprintf(buf, 1024, "%-5.5s %-9.9s %-10.10s %-10.10s %s", 159 snprintf(buf, 1024, "%-5.5s %-9.9s %-10.10s %-10.10s %s",
160 pidstr, ptruser, ptrrx, ptrtx, ptrcmd); 160 pidstr, ptruser, ptrrx, ptrtx, ptrcmd);
161 if (col < 1024) 161 if (col < 1024)
162 buf[col] = '\0'; 162 buf[col] = '\0';
163 printf("%s\n", buf); 163 printf("%s\n", buf);
164 164
165 if (cmd) 165 if (cmd)
166 free(cmd); 166 free(cmd);
167 if (user) 167 if (user)
168 free(user); 168 free(user);
169 169
170} 170}
171 171
172void netstats(void) { 172void netstats(void) {
173 pid_read(0); // include all processes 173 pid_read(0); // include all processes
174 174
175 printf("Displaying network statistics only for sandboxes using a new network namespace.\n"); 175 printf("Displaying network statistics only for sandboxes using a new network namespace.\n");
176 176
177 // print processes 177 // print processes
178 while (1) { 178 while (1) {
179 // set pid table 179 // set pid table
@@ -186,10 +186,10 @@ void netstats(void) {
186 if (pids[i].level == 1) 186 if (pids[i].level == 1)
187 get_stats(i); 187 get_stats(i);
188 } 188 }
189 189
190 // wait 5 seconds 190 // wait 5 seconds
191 firemon_sleep(itv); 191 firemon_sleep(itv);
192 192
193 // grab screen size 193 // grab screen size
194 struct winsize sz; 194 struct winsize sz;
195 int row = 24; 195 int row = 24;
@@ -198,7 +198,7 @@ void netstats(void) {
198 col = sz.ws_col; 198 col = sz.ws_col;
199 row = sz.ws_row; 199 row = sz.ws_row;
200 } 200 }
201 201
202 // start printing 202 // start printing
203 firemon_clrscr(); 203 firemon_clrscr();
204 char *header = get_header(); 204 char *header = get_header();
@@ -221,4 +221,3 @@ void netstats(void) {
221#endif 221#endif
222 } 222 }
223} 223}
224
diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c
index 378bdefe9..d6afed93a 100644
--- a/src/firemon/procevent.c
+++ b/src/firemon/procevent.c
@@ -40,12 +40,12 @@ static int pid_is_firejail(pid_t pid) {
40 printf("%s: %d, pid %d\n", __FUNCTION__, __LINE__, pid); 40 printf("%s: %d, pid %d\n", __FUNCTION__, __LINE__, pid);
41#endif 41#endif
42 uid_t rv = 0; 42 uid_t rv = 0;
43 43
44 // open /proc/self/comm 44 // open /proc/self/comm
45 char *file; 45 char *file;
46 if (asprintf(&file, "/proc/%u/comm", pid) == -1) 46 if (asprintf(&file, "/proc/%u/comm", pid) == -1)
47 errExit("asprintf"); 47 errExit("asprintf");
48 48
49 FILE *fp = fopen(file, "r"); 49 FILE *fp = fopen(file, "r");
50 if (!fp) { 50 if (!fp) {
51 free(file); 51 free(file);
@@ -58,7 +58,7 @@ static int pid_is_firejail(pid_t pid) {
58 if (strncmp(buf, "firejail", 8) == 0) 58 if (strncmp(buf, "firejail", 8) == 0)
59 rv = 1; 59 rv = 1;
60 } 60 }
61 61
62#ifdef DEBUG_PRCTL 62#ifdef DEBUG_PRCTL
63 printf("%s: %d, comm %s, rv %d\n", __FUNCTION__, __LINE__, buf, rv); 63 printf("%s: %d, comm %s, rv %d\n", __FUNCTION__, __LINE__, buf, rv);
64#endif 64#endif
@@ -76,7 +76,7 @@ static int pid_is_firejail(pid_t pid) {
76 goto doexit; 76 goto doexit;
77 } 77 }
78 free(fname); 78 free(fname);
79 79
80 // read file 80 // read file
81#define BUFLEN 4096 81#define BUFLEN 4096
82 unsigned char buffer[BUFLEN]; 82 unsigned char buffer[BUFLEN];
@@ -90,16 +90,16 @@ static int pid_is_firejail(pid_t pid) {
90 } 90 }
91 buffer[len] = '\0'; 91 buffer[len] = '\0';
92 close(fd); 92 close(fd);
93 93
94 // list of firejail arguments that don't trigger sandbox creation 94 // list of firejail arguments that don't trigger sandbox creation
95 // the initial -- is not included 95 // the initial -- is not included
96 char *exclude_args[] = { 96 char *exclude_args[] = {
97 "ls", "list", "tree", "x11", "help", "version", "top", "netstats", "debug-syscalls", 97 "ls", "list", "tree", "x11", "help", "version", "top", "netstats", "debug-syscalls",
98 "debug-errnos", "debug-protocols", "protocol.print", "debug.caps", 98 "debug-errnos", "debug-protocols", "protocol.print", "debug.caps",
99 "shutdown", "bandwidth", "caps.print", "cpu.print", "debug-caps", 99 "shutdown", "bandwidth", "caps.print", "cpu.print", "debug-caps",
100 "fs.print", "get", "overlay-clean", NULL 100 "fs.print", "get", "overlay-clean", NULL
101 }; 101 };
102 102
103 int i; 103 int i;
104 char *start; 104 char *start;
105 int first = 1; 105 int first = 1;
@@ -114,30 +114,30 @@ static int pid_is_firejail(pid_t pid) {
114 if (strncmp(start, "--", 2) != 0) 114 if (strncmp(start, "--", 2) != 0)
115 break; 115 break;
116 start += 2; 116 start += 2;
117 117
118 // clan starting with = 118 // clan starting with =
119 char *ptr = strchr(start, '='); 119 char *ptr = strchr(start, '=');
120 if (ptr) 120 if (ptr)
121 *ptr = '\0'; 121 *ptr = '\0';
122 122
123 // look into exclude list 123 // look into exclude list
124 int j = 0; 124 int j = 0;
125 while (exclude_args[j] != NULL) { 125 while (exclude_args[j] != NULL) {
126 if (strcmp(start, exclude_args[j]) == 0) { 126 if (strcmp(start, exclude_args[j]) == 0) {
127 rv = 0; 127 rv = 0;
128#ifdef DEBUG_PRCTL 128#ifdef DEBUG_PRCTL
129printf("start=#%s#, ptr=#%s#, flip rv %d\n", start, ptr, rv); 129printf("start=#%s#, ptr=#%s#, flip rv %d\n", start, ptr, rv);
130#endif 130#endif
131 break; 131 break;
132 } 132 }
133 j++; 133 j++;
134 } 134 }
135 135
136 start = (char *) buffer + i + 1; 136 start = (char *) buffer + i + 1;
137 } 137 }
138 } 138 }
139 139
140doexit: 140doexit:
141 fclose(fp); 141 fclose(fp);
142 free(file); 142 free(file);
143#ifdef DEBUG_PRCTL 143#ifdef DEBUG_PRCTL
@@ -187,7 +187,7 @@ static int procevent_netlink_setup(void) {
187 187
188 if (writev(sock, iov, 3) == -1) 188 if (writev(sock, iov, 3) == -1)
189 goto errexit; 189 goto errexit;
190 190
191 return sock; 191 return sock;
192errexit: 192errexit:
193 fprintf(stderr, "Error: netlink socket problem\n"); 193 fprintf(stderr, "Error: netlink socket problem\n");
@@ -209,29 +209,29 @@ static int procevent_monitor(const int sock, pid_t mypid) {
209 __gcov_flush(); 209 __gcov_flush();
210#endif 210#endif
211 211
212#define BUFFSIZE 4096 212#define BUFFSIZE 4096
213 char __attribute__ ((aligned(NLMSG_ALIGNTO)))buf[BUFFSIZE]; 213 char __attribute__ ((aligned(NLMSG_ALIGNTO)))buf[BUFFSIZE];
214 214
215 fd_set readfds; 215 fd_set readfds;
216 int max; 216 int max;
217 FD_ZERO(&readfds); 217 FD_ZERO(&readfds);
218 FD_SET(sock, &readfds); 218 FD_SET(sock, &readfds);
219 max = sock; 219 max = sock;
220 max++; 220 max++;
221 221
222 int rv = select(max, &readfds, NULL, NULL, &tv); 222 int rv = select(max, &readfds, NULL, NULL, &tv);
223 if (rv == -1) { 223 if (rv == -1) {
224 fprintf(stderr, "recv: %s\n", strerror(errno)); 224 fprintf(stderr, "recv: %s\n", strerror(errno));
225 return -1; 225 return -1;
226 } 226 }
227 227
228 // timeout 228 // timeout
229 if (rv == 0) { 229 if (rv == 0) {
230 tv.tv_sec = 30; 230 tv.tv_sec = 30;
231 tv.tv_usec = 0; 231 tv.tv_usec = 0;
232 continue; 232 continue;
233 } 233 }
234 234
235 235
236 if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) { 236 if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) {
237 return 0; 237 return 0;
@@ -304,7 +304,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
304 } 304 }
305 sprintf(lineptr, " exec"); 305 sprintf(lineptr, " exec");
306 break; 306 break;
307 307
308 case PROC_EVENT_EXIT: 308 case PROC_EVENT_EXIT:
309 if (proc_ev->event_data.exit.process_pid != 309 if (proc_ev->event_data.exit.process_pid !=
310 proc_ev->event_data.exit.process_tgid) 310 proc_ev->event_data.exit.process_tgid)
@@ -317,7 +317,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
317 remove_pid = 1; 317 remove_pid = 1;
318 sprintf(lineptr, " exit"); 318 sprintf(lineptr, " exit");
319 break; 319 break;
320 320
321 case PROC_EVENT_UID: 321 case PROC_EVENT_UID:
322 pid = proc_ev->event_data.id.process_tgid; 322 pid = proc_ev->event_data.id.process_tgid;
323#ifdef DEBUG_PRCTL 323#ifdef DEBUG_PRCTL
@@ -363,11 +363,11 @@ static int procevent_monitor(const int sock, pid_t mypid) {
363 continue; 363 continue;
364 } 364 }
365 } 365 }
366 366
367 lineptr += strlen(lineptr); 367 lineptr += strlen(lineptr);
368 sprintf(lineptr, " %u", pid); 368 sprintf(lineptr, " %u", pid);
369 lineptr += strlen(lineptr); 369 lineptr += strlen(lineptr);
370 370
371 char *user = pids[pid].user; 371 char *user = pids[pid].user;
372 if (!user) 372 if (!user)
373 user = pid_get_user_name(pids[pid].uid); 373 user = pid_get_user_name(pids[pid].uid);
@@ -376,7 +376,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
376 sprintf(lineptr, " (%s)", user); 376 sprintf(lineptr, " (%s)", user);
377 lineptr += strlen(lineptr); 377 lineptr += strlen(lineptr);
378 } 378 }
379 379
380 380
381 int sandbox_closed = 0; // exit sandbox flag 381 int sandbox_closed = 0; // exit sandbox flag
382 char *cmd = pids[pid].cmd; 382 char *cmd = pids[pid].cmd;
@@ -409,11 +409,11 @@ static int procevent_monitor(const int sock, pid_t mypid) {
409 lineptr += strlen(lineptr); 409 lineptr += strlen(lineptr);
410 } 410 }
411 (void) lineptr; 411 (void) lineptr;
412 412
413 // print the event 413 // print the event
414 printf("%s", line); 414 printf("%s", line);
415 fflush(0); 415 fflush(0);
416 416
417 // unflag pid for exit events 417 // unflag pid for exit events
418 if (remove_pid) { 418 if (remove_pid) {
419 if (pids[pid].user) 419 if (pids[pid].user)
@@ -433,15 +433,15 @@ static int procevent_monitor(const int sock, pid_t mypid) {
433 else 433 else
434 printf("\tchild %u\n", child); 434 printf("\tchild %u\n", child);
435 } 435 }
436 436
437 // on uid events the uid is changing 437 // on uid events the uid is changing
438 if (proc_ev->what == PROC_EVENT_UID) { 438 if (proc_ev->what == PROC_EVENT_UID) {
439 if (pids[pid].user) 439 if (pids[pid].user)
440 free(pids[pid].user); 440 free(pids[pid].user);
441 pids[pid].user = 0; 441 pids[pid].user = 0;
442 pids[pid].uid = pid_get_uid(pid); 442 pids[pid].uid = pid_get_uid(pid);
443 } 443 }
444 444
445 if (sandbox_closed) 445 if (sandbox_closed)
446 exit(0); 446 exit(0);
447 } 447 }
diff --git a/src/firemon/route.c b/src/firemon/route.c
index 145daa152..f083ada0b 100644
--- a/src/firemon/route.c
+++ b/src/firemon/route.c
@@ -36,7 +36,7 @@ static IfList *list_find(uint32_t ip, uint32_t mask) {
36 return ptr; 36 return ptr;
37 ptr = ptr->next; 37 ptr = ptr->next;
38 } 38 }
39 39
40 return NULL; 40 return NULL;
41} 41}
42 42
@@ -47,15 +47,15 @@ static void extract_if(const char *fname) {
47 free(ifs); 47 free(ifs);
48 ifs = tmp; 48 ifs = tmp;
49 } 49 }
50 assert(ifs == NULL); 50 assert(ifs == NULL);
51 51
52 FILE *fp = fopen(fname, "r"); 52 FILE *fp = fopen(fname, "r");
53 if (!fp) 53 if (!fp)
54 return; 54 return;
55 55
56 char buf[MAXBUF]; 56 char buf[MAXBUF];
57 int state = 0; // 0 -wait for Local 57 int state = 0; // 0 -wait for Local
58 // 58 //
59 while (fgets(buf, MAXBUF, fp)) { 59 while (fgets(buf, MAXBUF, fp)) {
60 // remove blanks, \n 60 // remove blanks, \n
61 char *ptr = buf; 61 char *ptr = buf;
@@ -67,7 +67,7 @@ static void extract_if(const char *fname) {
67 ptr = strchr(ptr, '\n'); 67 ptr = strchr(ptr, '\n');
68 if (ptr) 68 if (ptr)
69 *ptr = '\0'; 69 *ptr = '\0';
70 70
71 if (state == 0) { 71 if (state == 0) {
72 if (strncmp(buf, "Local:", 6) == 0) { 72 if (strncmp(buf, "Local:", 6) == 0) {
73 state = 1; 73 state = 1;
@@ -105,7 +105,7 @@ static void extract_if(const char *fname) {
105 } 105 }
106 } 106 }
107 } 107 }
108 108
109 fclose(fp); 109 fclose(fp);
110 110
111 111
@@ -115,7 +115,7 @@ static void print_route(const char *fname) {
115 FILE *fp = fopen(fname, "r"); 115 FILE *fp = fopen(fname, "r");
116 if (!fp) 116 if (!fp)
117 return; 117 return;
118 118
119 printf(" Route table:\n"); 119 printf(" Route table:\n");
120 char buf[MAXBUF]; 120 char buf[MAXBUF];
121 while (fgets(buf, MAXBUF, fp)) { 121 while (fgets(buf, MAXBUF, fp)) {
@@ -147,7 +147,7 @@ static void print_route(const char *fname) {
147 int rv = sscanf(start, "%s %s %s %s %s %s %s %s\n", ifname, destination, gateway, flags, refcnt, use, metric, mask); 147 int rv = sscanf(start, "%s %s %s %s %s %s %s %s\n", ifname, destination, gateway, flags, refcnt, use, metric, mask);
148 if (rv != 8) 148 if (rv != 8)
149 continue; 149 continue;
150 150
151 // destination ip 151 // destination ip
152 uint32_t destip; 152 uint32_t destip;
153 sscanf(destination, "%x", &destip); 153 sscanf(destination, "%x", &destip);
@@ -158,7 +158,7 @@ static void print_route(const char *fname) {
158 uint32_t gw; 158 uint32_t gw;
159 sscanf(gateway, "%x", &gw); 159 sscanf(gateway, "%x", &gw);
160 gw = ntohl(gw); 160 gw = ntohl(gw);
161 161
162// printf("#%s# #%s# #%s# #%s# #%s# #%s# #%s# #%s#\n", ifname, destination, gateway, flags, refcnt, use, metric, mask); 162// printf("#%s# #%s# #%s# #%s# #%s# #%s# #%s# #%s#\n", ifname, destination, gateway, flags, refcnt, use, metric, mask);
163 if (gw != 0) 163 if (gw != 0)
164 printf(" %u.%u.%u.%u/%u via %u.%u.%u.%u, dev %s, metric %s\n", 164 printf(" %u.%u.%u.%u/%u via %u.%u.%u.%u, dev %s, metric %s\n",
@@ -176,14 +176,14 @@ static void print_route(const char *fname) {
176 } 176 }
177 } 177 }
178 } 178 }
179 179
180 fclose(fp); 180 fclose(fp);
181 181
182} 182}
183 183
184void route(pid_t pid, int print_procs) { 184void route(pid_t pid, int print_procs) {
185 pid_read(pid); 185 pid_read(pid);
186 186
187 // print processes 187 // print processes
188 int i; 188 int i;
189 for (i = 0; i < max_pids; i++) { 189 for (i = 0; i < max_pids; i++) {
@@ -207,5 +207,3 @@ void route(pid_t pid, int print_procs) {
207 } 207 }
208 printf("\n"); 208 printf("\n");
209} 209}
210
211
diff --git a/src/firemon/seccomp.c b/src/firemon/seccomp.c
index e530fa1c3..73d962fc9 100644
--- a/src/firemon/seccomp.c
+++ b/src/firemon/seccomp.c
@@ -31,7 +31,7 @@ static void print_seccomp(int pid) {
31 free(file); 31 free(file);
32 return; 32 return;
33 } 33 }
34 34
35 char buf[MAXBUF]; 35 char buf[MAXBUF];
36 while (fgets(buf, MAXBUF, fp)) { 36 while (fgets(buf, MAXBUF, fp)) {
37 if (strncmp(buf, "Seccomp:", 8) == 0) { 37 if (strncmp(buf, "Seccomp:", 8) == 0) {
@@ -43,10 +43,10 @@ static void print_seccomp(int pid) {
43 fclose(fp); 43 fclose(fp);
44 free(file); 44 free(file);
45} 45}
46 46
47void seccomp(pid_t pid, int print_procs) { 47void seccomp(pid_t pid, int print_procs) {
48 pid_read(pid); // include all processes 48 pid_read(pid); // include all processes
49 49
50 // print processes 50 // print processes
51 int i; 51 int i;
52 for (i = 0; i < max_pids; i++) { 52 for (i = 0; i < max_pids; i++) {
@@ -60,4 +60,3 @@ void seccomp(pid_t pid, int print_procs) {
60 } 60 }
61 printf("\n"); 61 printf("\n");
62} 62}
63
diff --git a/src/firemon/top.c b/src/firemon/top.c
index 081f04eba..fc6e6289e 100644
--- a/src/firemon/top.c
+++ b/src/firemon/top.c
@@ -23,7 +23,7 @@
23#include <sys/types.h> 23#include <sys/types.h>
24#include <sys/stat.h> 24#include <sys/stat.h>
25#include <unistd.h> 25#include <unistd.h>
26 26
27static unsigned pgs_rss = 0; 27static unsigned pgs_rss = 0;
28static unsigned pgs_shared = 0; 28static unsigned pgs_shared = 0;
29static unsigned clocktick = 0; 29static unsigned clocktick = 0;
@@ -40,7 +40,7 @@ static char *get_user_name(uid_t uid) {
40 } 40 }
41 else if (uid == cached_uid) 41 else if (uid == cached_uid)
42 return strdup(cached_user_name); 42 return strdup(cached_user_name);
43 else 43 else
44 return pid_get_user_name(uid); 44 return pid_get_user_name(uid);
45} 45}
46 46
@@ -49,7 +49,7 @@ static char *get_header(void) {
49 if (asprintf(&rv, "%-5.5s %-9.9s %-8.8s %-8.8s %-5.5s %-4.4s %-9.9s %s", 49 if (asprintf(&rv, "%-5.5s %-9.9s %-8.8s %-8.8s %-5.5s %-4.4s %-9.9s %s",
50 "PID", "User", "RES(KiB)", "SHR(KiB)", "CPU%", "Prcs", "Uptime", "Command") == -1) 50 "PID", "User", "RES(KiB)", "SHR(KiB)", "CPU%", "Prcs", "Uptime", "Command") == -1)
51 errExit("asprintf"); 51 errExit("asprintf");
52 52
53 return rv; 53 return rv;
54} 54}
55 55
@@ -66,7 +66,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
66 struct stat s; 66 struct stat s;
67 if (stat(procdir, &s) == -1) 67 if (stat(procdir, &s) == -1)
68 return NULL; 68 return NULL;
69 69
70 if (pids[index].level == 1) { 70 if (pids[index].level == 1) {
71 pgs_rss = 0; 71 pgs_rss = 0;
72 pgs_shared = 0; 72 pgs_shared = 0;
@@ -74,7 +74,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
74 *stime = 0; 74 *stime = 0;
75 *cnt = 0; 75 *cnt = 0;
76 } 76 }
77 77
78 (*cnt)++; 78 (*cnt)++;
79 pid_getmem(index, &pgs_rss, &pgs_shared); 79 pid_getmem(index, &pgs_rss, &pgs_shared);
80 unsigned utmp; 80 unsigned utmp;
@@ -82,8 +82,8 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
82 pid_get_cpu_time(index, &utmp, &stmp); 82 pid_get_cpu_time(index, &utmp, &stmp);
83 *utime += utmp; 83 *utime += utmp;
84 *stime += stmp; 84 *stime += stmp;
85 85
86 86
87 int i; 87 int i;
88 for (i = index + 1; i < max_pids; i++) { 88 for (i = index + 1; i < max_pids; i++) {
89 if (pids[i].parent == (pid_t)index) 89 if (pids[i].parent == (pid_t)index)
@@ -108,7 +108,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
108 ptrcmd = cmd + 9; 108 ptrcmd = cmd + 9;
109 else 109 else
110 ptrcmd = cmd; 110 ptrcmd = cmd;
111 111
112 // user 112 // user
113 char *user = get_user_name(pids[index].uid); 113 char *user = get_user_name(pids[index].uid);
114 char *ptruser; 114 char *ptruser;
@@ -116,7 +116,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
116 ptruser = user; 116 ptruser = user;
117 else 117 else
118 ptruser = ""; 118 ptruser = "";
119 119
120 // memory 120 // memory
121 if (pgsz == 0) 121 if (pgsz == 0)
122 pgsz = getpagesize(); 122 pgsz = getpagesize();
@@ -124,7 +124,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
124 snprintf(rss, 10, "%u", pgs_rss * pgsz / 1024); 124 snprintf(rss, 10, "%u", pgs_rss * pgsz / 1024);
125 char shared[10]; 125 char shared[10];
126 snprintf(shared, 10, "%u", pgs_shared * pgsz / 1024); 126 snprintf(shared, 10, "%u", pgs_shared * pgsz / 1024);
127 127
128 // uptime 128 // uptime
129 unsigned long long uptime = pid_get_start_time(index); 129 unsigned long long uptime = pid_get_start_time(index);
130 if (clocktick == 0) 130 if (clocktick == 0)
@@ -140,7 +140,7 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
140 unsigned hour = uptime; 140 unsigned hour = uptime;
141 char uptime_str[50]; 141 char uptime_str[50];
142 snprintf(uptime_str, 50, "%02u:%02u:%02u", hour, min, sec); 142 snprintf(uptime_str, 50, "%02u:%02u:%02u", hour, min, sec);
143 143
144 // cpu 144 // cpu
145 itv *= clocktick; 145 itv *= clocktick;
146 float ud = (float) (*utime - pids[index].utime) / itv * 100; 146 float ud = (float) (*utime - pids[index].utime) / itv * 100;
@@ -153,18 +153,18 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
153 // process count 153 // process count
154 char prcs_str[10]; 154 char prcs_str[10];
155 snprintf(prcs_str, 10, "%d", *cnt); 155 snprintf(prcs_str, 10, "%d", *cnt);
156 156
157 if (asprintf(&rv, "%-5.5s %-9.9s %-8.8s %-8.8s %-5.5s %-4.4s %-9.9s %s", 157 if (asprintf(&rv, "%-5.5s %-9.9s %-8.8s %-8.8s %-5.5s %-4.4s %-9.9s %s",
158 pidstr, ptruser, rss, shared, cpu_str, prcs_str, uptime_str, ptrcmd) == -1) 158 pidstr, ptruser, rss, shared, cpu_str, prcs_str, uptime_str, ptrcmd) == -1)
159 errExit("asprintf"); 159 errExit("asprintf");
160 160
161 if (cmd) 161 if (cmd)
162 free(cmd); 162 free(cmd);
163 if (user) 163 if (user)
164 free(user); 164 free(user);
165 165
166 } 166 }
167 167
168 return rv; 168 return rv;
169} 169}
170 170
@@ -174,7 +174,7 @@ typedef struct node_t {
174 char *line; 174 char *line;
175 float cpu; 175 float cpu;
176} Node; 176} Node;
177 177
178static Node *head = NULL; 178static Node *head = NULL;
179 179
180static void head_clear(void) { 180static void head_clear(void) {
@@ -186,7 +186,7 @@ static void head_clear(void) {
186 free(ptr); 186 free(ptr);
187 ptr = next; 187 ptr = next;
188 } 188 }
189 189
190 head = NULL; 190 head = NULL;
191} 191}
192 192
@@ -198,14 +198,14 @@ static void head_add(float cpu, char *line) {
198 node->line = line; 198 node->line = line;
199 node->cpu = cpu; 199 node->cpu = cpu;
200 node->next = NULL; 200 node->next = NULL;
201 201
202 // insert in first list position 202 // insert in first list position
203 if (head == NULL || head->cpu < cpu) { 203 if (head == NULL || head->cpu < cpu) {
204 node->next = head; 204 node->next = head;
205 head = node; 205 head = node;
206 return; 206 return;
207 } 207 }
208 208
209 // insert in the right place 209 // insert in the right place
210 Node *ptr = head; 210 Node *ptr = head;
211 while (1) { 211 while (1) {
@@ -215,14 +215,14 @@ static void head_add(float cpu, char *line) {
215 ptr->next = node; 215 ptr->next = node;
216 return; 216 return;
217 } 217 }
218 218
219 // current position 219 // current position
220 if (current->cpu < cpu) { 220 if (current->cpu < cpu) {
221 ptr->next = node; 221 ptr->next = node;
222 node->next = current; 222 node->next = current;
223 return; 223 return;
224 } 224 }
225 225
226 ptr = current; 226 ptr = current;
227 } 227 }
228} 228}
@@ -233,10 +233,10 @@ void head_print(int col, int row) {
233 while (ptr) { 233 while (ptr) {
234 if (current >= row) 234 if (current >= row)
235 break; 235 break;
236 236
237 if (strlen(ptr->line) > (size_t)col) 237 if (strlen(ptr->line) > (size_t)col)
238 ptr->line[col] = '\0'; 238 ptr->line[col] = '\0';
239 239
240 if (ptr->next == NULL || current == (row - 1)) { 240 if (ptr->next == NULL || current == (row - 1)) {
241 printf("%s", ptr->line); 241 printf("%s", ptr->line);
242 fflush(0); 242 fflush(0);
@@ -253,7 +253,7 @@ void top(void) {
253 while (1) { 253 while (1) {
254 // clear linked list 254 // clear linked list
255 head_clear(); 255 head_clear();
256 256
257 // set pid table 257 // set pid table
258 int i; 258 int i;
259 int itv = 1; // 1 second interval 259 int itv = 1; // 1 second interval
@@ -266,10 +266,10 @@ void top(void) {
266 if (pids[i].level == 1) 266 if (pids[i].level == 1)
267 pid_store_cpu(i, 0, &utime, &stime); 267 pid_store_cpu(i, 0, &utime, &stime);
268 } 268 }
269 269
270 // wait 1 second 270 // wait 1 second
271 firemon_sleep(itv); 271 firemon_sleep(itv);
272 272
273 // grab screen size 273 // grab screen size
274 struct winsize sz; 274 struct winsize sz;
275 int row = 24; 275 int row = 24;
@@ -288,7 +288,7 @@ void top(void) {
288 if (row > 0) 288 if (row > 0)
289 row--; 289 row--;
290 free(header); 290 free(header);
291 291
292 // find system uptime 292 // find system uptime
293 FILE *fp = fopen("/proc/uptime", "r"); 293 FILE *fp = fopen("/proc/uptime", "r");
294 if (fp) { 294 if (fp) {
@@ -315,4 +315,3 @@ void top(void) {
315#endif 315#endif
316 } 316 }
317} 317}
318
diff --git a/src/firemon/tree.c b/src/firemon/tree.c
index 3fdcc4d37..99f68c262 100644
--- a/src/firemon/tree.c
+++ b/src/firemon/tree.c
@@ -21,7 +21,7 @@
21 21
22void tree(pid_t pid) { 22void tree(pid_t pid) {
23 pid_read(pid); 23 pid_read(pid);
24 24
25 // print processes 25 // print processes
26 int i; 26 int i;
27 for (i = 0; i < max_pids; i++) { 27 for (i = 0; i < max_pids; i++) {
@@ -30,4 +30,3 @@ void tree(pid_t pid) {
30 } 30 }
31 printf("\n"); 31 printf("\n");
32} 32}
33
diff --git a/src/firemon/x11.c b/src/firemon/x11.c
index c923c8ef8..7e331795f 100644
--- a/src/firemon/x11.c
+++ b/src/firemon/x11.c
@@ -21,17 +21,17 @@
21#include <sys/types.h> 21#include <sys/types.h>
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <unistd.h> 23#include <unistd.h>
24 24
25void x11(pid_t pid, int print_procs) { 25void x11(pid_t pid, int print_procs) {
26 pid_read(pid); 26 pid_read(pid);
27 27
28 // print processes 28 // print processes
29 int i; 29 int i;
30 for (i = 0; i < max_pids; i++) { 30 for (i = 0; i < max_pids; i++) {
31 if (pids[i].level == 1) { 31 if (pids[i].level == 1) {
32 if (print_procs || pid == 0) 32 if (print_procs || pid == 0)
33 pid_print_list(i, arg_nowrap); 33 pid_print_list(i, arg_nowrap);
34 34
35 char *x11file; 35 char *x11file;
36 // todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory 36 // todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory
37 if (asprintf(&x11file, "/run/firejail/x11/%d", i) == -1) 37 if (asprintf(&x11file, "/run/firejail/x11/%d", i) == -1)
@@ -53,4 +53,3 @@ void x11(pid_t pid, int print_procs) {
53 } 53 }
54 printf("\n"); 54 printf("\n");
55} 55}
56