Skip to content

Commit

Permalink
fix and document firemon --nowrap
Browse files Browse the repository at this point in the history
  • Loading branch information
netblue30 committed Mar 4, 2017
1 parent 791aa95 commit d9c217d
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/firemon/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void arp(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1) {
char *fname;
Expand Down
6 changes: 2 additions & 4 deletions src/firemon/caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ static void print_caps(int pid) {
if (strncmp(buf, "CapBnd:", 7) == 0) {
printf(" %s", buf);
fflush(0);
free(file);
fclose(fp);
return;
break;
}
}
fclose(fp);
Expand All @@ -55,7 +53,7 @@ void caps(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1)
print_caps(child);
Expand Down
2 changes: 1 addition & 1 deletion src/firemon/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void cgroup(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1)
print_cgroup(child);
Expand Down
6 changes: 2 additions & 4 deletions src/firemon/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ static void print_cpu(int pid) {
if (strncmp(buf, "Cpus_allowed_list:", 18) == 0) {
printf(" %s", buf);
fflush(0);
free(file);
fclose(fp);
return;
break;
}
}
fclose(fp);
Expand All @@ -56,7 +54,7 @@ void cpu(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1)
print_cpu(child);
Expand Down
2 changes: 1 addition & 1 deletion src/firemon/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void interface(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1) {
print_sandbox(child);
Expand Down
2 changes: 1 addition & 1 deletion src/firemon/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void list(void) {
int i;
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
}
}

21 changes: 9 additions & 12 deletions src/firemon/procevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,17 @@ printf("start=#%s#, ptr=#%s#, flip rv %d\n", start, ptr, rv);
static int procevent_netlink_setup(void) {
// open socket for process event connector
int sock;
if ((sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR)) < 0) {
fprintf(stderr, "Error: cannot open netlink socket\n");
exit(1);
}
if ((sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR)) < 0)
goto errexit;

// bind socket
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_pid = getpid();
addr.nl_family = AF_NETLINK;
addr.nl_groups = CN_IDX_PROC;
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "Error: cannot bind to netlink socket\n");
exit(1);
}
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
goto errexit;

// send monitoring message
struct nlmsghdr nlmsghdr;
Expand All @@ -189,12 +185,13 @@ static int procevent_netlink_setup(void) {
iov[2].iov_base = &op;
iov[2].iov_len = sizeof(op);

if (writev(sock, iov, 3) == -1) {
fprintf(stderr, "Error: cannot write to netlink socket\n");
exit(1);
}
if (writev(sock, iov, 3) == -1)
goto errexit;

return sock;
errexit:
fprintf(stderr, "Error: netlink socket problem\n");
exit(1);
}


Expand Down
2 changes: 1 addition & 1 deletion src/firemon/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void route(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1) {
char *fname;
Expand Down
6 changes: 2 additions & 4 deletions src/firemon/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ static void print_seccomp(int pid) {
if (strncmp(buf, "Seccomp:", 8) == 0) {
printf(" %s", buf);
fflush(0);
fclose(fp);
free(file);
return;
break;
}
}
fclose(fp);
Expand All @@ -54,7 +52,7 @@ void seccomp(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);
int child = find_child(i);
if (child != -1)
print_seccomp(child);
Expand Down
1 change: 1 addition & 0 deletions src/firemon/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void usage(void) {
printf("\t--name=name - print information only about named sandbox.\n\n");
printf("\t--netstats - monitor network statistics for sandboxes creating a new\n");
printf("\t\tnetwork namespace.\n\n");
printf("\t--nowrap - enable line wrapping in terminals.\n\n");
printf("\t--route - print route table for each sandbox.\n\n");
printf("\t--seccomp - print seccomp configuration for each sandbox.\n\n");
printf("\t--tree - print a tree of all sandboxed processes.\n\n");
Expand Down
2 changes: 1 addition & 1 deletion src/firemon/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void x11(pid_t pid, int print_procs) {
for (i = 0; i < max_pids; i++) {
if (pids[i].level == 1) {
if (print_procs || pid == 0)
pid_print_list(i, 0);
pid_print_list(i, arg_nowrap);

char *x11file;
// todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory
Expand Down
3 changes: 3 additions & 0 deletions src/man/firemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Print information only about named sandbox.
\fB\-\-netstats
Monitor network statistics for sandboxes creating a new network namespace.
.TP
\fB\-\-nowrap
Enable line wrapping in terminals. By default the lines are trimmed.
.TP
\fB\-\-route
Print route table for each sandbox.
.TP
Expand Down
4 changes: 2 additions & 2 deletions test/apps-x11-xorg/firefox.exp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ expect {
sleep 2

spawn $env(SHELL)
send -- "firemon --seccomp\r"
send -- "firemon --seccomp --nowrap\r"
expect {
timeout {puts "TESTING ERROR 5\n";exit}
"need to be root" {puts "/proc mounted as hidepid, exiting...\n"; exit}
Expand All @@ -61,7 +61,7 @@ expect {
"name=blablabla"
}
sleep 1
send -- "firemon --caps\r"
send -- "firemon --caps --nowrap\r"
expect {
timeout {puts "TESTING ERROR 6\n";exit}
" firefox" {puts "firefox detected\n";}
Expand Down
4 changes: 2 additions & 2 deletions test/apps-x11-xorg/icedove.exp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ expect {
sleep 2

spawn $env(SHELL)
send -- "firemon --seccomp\r"
send -- "firemon --seccomp --nowrap\r"
expect {
timeout {puts "TESTING ERROR 5\n";exit}
"need to be root" {puts "/proc mounted as hidepid, exiting...\n"; exit}
Expand All @@ -57,7 +57,7 @@ expect {
"name=blablabla"
}
sleep 2
send -- "firemon --caps\r"
send -- "firemon --caps --nowrap\r"
expect {
timeout {puts "TESTING ERROR 6\n";exit}
":firejail"
Expand Down
4 changes: 2 additions & 2 deletions test/apps-x11-xorg/transmission-gtk.exp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ expect {
sleep 2

spawn $env(SHELL)
send -- "firemon --seccomp\r"
send -- "firemon --seccomp --nowrap\r"
expect {
timeout {puts "TESTING ERROR 5\n";exit}
"need to be root" {puts "/proc mounted as hidepid, exiting...\n"; exit}
Expand All @@ -57,7 +57,7 @@ expect {
"name=blablabla"
}
sleep 1
send -- "firemon --caps\r"
send -- "firemon --caps --nowrap\r"
expect {
timeout {puts "TESTING ERROR 6\n";exit}
":firejail"
Expand Down

0 comments on commit d9c217d

Please sign in to comment.