aboutsummaryrefslogtreecommitdiffstats
path: root/src/firemon
diff options
context:
space:
mode:
authorLibravatar startx2017 <vradu.startx@yandex.com>2018-09-06 09:02:13 -0400
committerLibravatar startx2017 <vradu.startx@yandex.com>2018-09-06 09:02:13 -0400
commitb98be56e934c9bd52bebbc7d506fbf6f8b75a237 (patch)
treefbc62858525fb67be4c4b14aa7d411c5d6b79592 /src/firemon
parentfinal cleanup (diff)
downloadfirejail-b98be56e934c9bd52bebbc7d506fbf6f8b75a237.tar.gz
firejail-b98be56e934c9bd52bebbc7d506fbf6f8b75a237.tar.zst
firejail-b98be56e934c9bd52bebbc7d506fbf6f8b75a237.zip
final cleanup
Diffstat (limited to 'src/firemon')
-rw-r--r--src/firemon/cgroup.c63
-rw-r--r--src/firemon/firemon.c18
-rw-r--r--src/firemon/x11.c55
3 files changed, 1 insertions, 135 deletions
diff --git a/src/firemon/cgroup.c b/src/firemon/cgroup.c
deleted file mode 100644
index 8dbf85824..000000000
--- a/src/firemon/cgroup.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * Copyright (C) 2014-2018 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include "firemon.h"
21#define MAXBUF 4098
22
23static void print_cgroup(int pid) {
24 char *file;
25 if (asprintf(&file, "/proc/%d/cgroup", pid) == -1) {
26 errExit("asprintf");
27 exit(1);
28 }
29
30 FILE *fp = fopen(file, "r");
31 if (!fp) {
32 printf(" Error: cannot open %s\n", file);
33 free(file);
34 return;
35 }
36
37 char buf[MAXBUF];
38 if (fgets(buf, MAXBUF, fp)) {
39 printf(" %s", buf);
40 fflush(0);
41 }
42
43 fclose(fp);
44 free(file);
45}
46
47void cgroup(pid_t pid, int print_procs) {
48 pid_read(pid);
49
50 // print processes
51 printf(" cgroup: ");
52 int i;
53 for (i = 0; i < max_pids; i++) {
54 if (pids[i].level == 1) {
55 if (print_procs || pid == 0)
56 pid_print_list(i, arg_nowrap);
57 int child = find_child(i);
58 if (child != -1)
59 print_cgroup(child);
60 }
61 }
62 printf("\n");
63}
diff --git a/src/firemon/firemon.c b/src/firemon/firemon.c
index 147b5073b..6124310b1 100644
--- a/src/firemon/firemon.c
+++ b/src/firemon/firemon.c
@@ -33,8 +33,6 @@ static int arg_interface = 0;
33static int arg_seccomp = 0; 33static int arg_seccomp = 0;
34static int arg_caps = 0; 34static int arg_caps = 0;
35static int arg_cpu = 0; 35static int arg_cpu = 0;
36static int arg_cgroup = 0;
37static int arg_x11 = 0;
38static int arg_top = 0; 36static int arg_top = 0;
39static int arg_list = 0; 37static int arg_list = 0;
40static int arg_netstats = 0; 38static int arg_netstats = 0;
@@ -159,10 +157,6 @@ int main(int argc, char **argv) {
159 157
160 158
161 // cumulative options with or without a pid argument 159 // cumulative options with or without a pid argument
162 else if (strcmp(argv[i], "--x11") == 0)
163 arg_x11 = 1;
164 else if (strcmp(argv[i], "--cgroup") == 0)
165 arg_cgroup = 1;
166 else if (strcmp(argv[i], "--cpu") == 0) 160 else if (strcmp(argv[i], "--cpu") == 0)
167 arg_cpu = 1; 161 arg_cpu = 1;
168 else if (strcmp(argv[i], "--seccomp") == 0) 162 else if (strcmp(argv[i], "--seccomp") == 0)
@@ -250,13 +244,11 @@ int main(int argc, char **argv) {
250 244
251 // if --name requested without other options, print all data 245 // if --name requested without other options, print all data
252 if (pid && !arg_cpu && !arg_seccomp && !arg_caps && !arg_apparmor && 246 if (pid && !arg_cpu && !arg_seccomp && !arg_caps && !arg_apparmor &&
253 !arg_cgroup && !arg_x11 && !arg_interface && !arg_route && !arg_arp) { 247 !arg_interface && !arg_route && !arg_arp) {
254 arg_tree = 1; 248 arg_tree = 1;
255 arg_cpu = 1; 249 arg_cpu = 1;
256 arg_seccomp = 1; 250 arg_seccomp = 1;
257 arg_caps = 1; 251 arg_caps = 1;
258 arg_cgroup = 1;
259 arg_x11 = 1;
260 arg_interface = 1; 252 arg_interface = 1;
261 arg_route = 1; 253 arg_route = 1;
262 arg_arp = 1; 254 arg_arp = 1;
@@ -281,14 +273,6 @@ int main(int argc, char **argv) {
281 apparmor((pid_t) pid, print_procs); 273 apparmor((pid_t) pid, print_procs);
282 print_procs = 0; 274 print_procs = 0;
283 } 275 }
284 if (arg_cgroup) {
285 cgroup((pid_t) pid, print_procs);
286 print_procs = 0;
287 }
288 if (arg_x11) {
289 x11((pid_t) pid, print_procs);
290 print_procs = 0;
291 }
292 if (arg_interface && getuid() == 0) { 276 if (arg_interface && getuid() == 0) {
293 interface((pid_t) pid, print_procs); 277 interface((pid_t) pid, print_procs);
294 print_procs = 0; 278 print_procs = 0;
diff --git a/src/firemon/x11.c b/src/firemon/x11.c
deleted file mode 100644
index 09eb3cd06..000000000
--- a/src/firemon/x11.c
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * Copyright (C) 2014-2018 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include "firemon.h"
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <unistd.h>
24
25void x11(pid_t pid, int print_procs) {
26 pid_read(pid);
27
28 // print processes
29 int i;
30 for (i = 0; i < max_pids; i++) {
31 if (pids[i].level == 1) {
32 if (print_procs || pid == 0)
33 pid_print_list(i, arg_nowrap);
34
35 char *x11file;
36 // todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory
37 if (asprintf(&x11file, "/run/firejail/x11/%d", i) == -1)
38 errExit("asprintf");
39
40 FILE *fp = fopen(x11file, "r");
41 if (!fp) {
42 free(x11file);
43 continue;
44 }
45
46 int display;
47 int rv = fscanf(fp, "%d", &display);
48 if (rv == 1)
49 printf(" DISPLAY :%d\n", display);
50 fclose(fp);
51 free(x11file);
52 }
53 }
54 printf("\n");
55}