Skip to content

Commit

Permalink
don't display firejail --list/--tree/--top processes in firemon stats
Browse files Browse the repository at this point in the history
  • Loading branch information
startx2017 committed May 8, 2018
1 parent 5031d16 commit 2a0fb5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/firemon/firemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <grp.h>
#include <sys/stat.h>

pid_t skip_process = 0;
static int arg_route = 0;
static int arg_arp = 0;
static int arg_tree = 0;
Expand Down Expand Up @@ -217,6 +218,13 @@ int main(int argc, char **argv) {
}
}


// if the parent is firejail, skip the process
pid_t ppid = getppid();
char *pcomm = pid_proc_comm(ppid);
if (pcomm && strcmp(pcomm, "firejail") == 0)
skip_process = ppid;

// allow only root user if /proc is mounted hidepid
if (pid_hidepid() && getuid() != 0) {
fprintf(stderr, "Error: /proc is mounted hidepid, you would need to be root to run this command\n");
Expand Down
1 change: 1 addition & 0 deletions src/firemon/firemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static inline void firemon_clrscr(void) {
}

// firemon.c
extern pid_t skip_process;
extern int arg_nowrap;
int find_child(int id);
void firemon_sleep(int st);
Expand Down
2 changes: 2 additions & 0 deletions src/firemon/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void list(void) {
// print processes
int i;
for (i = 0; i < max_pids; i++) {
if (i == skip_process)
continue;
if (pids[i].level == 1)
pid_print_list(i, arg_nowrap);
}
Expand Down
4 changes: 4 additions & 0 deletions src/firemon/top.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ void top(void) {
unsigned utime = 0;
unsigned stime = 0;
for (i = 0; i < max_pids; i++) {
if (i == skip_process)
continue;
if (pids[i].level == 1)
pid_store_cpu(i, 0, &utime, &stime);
}
Expand Down Expand Up @@ -313,6 +315,8 @@ void top(void) {

// print processes
for (i = 0; i < max_pids; i++) {
if (i == skip_process)
continue;
if (pids[i].level == 1) {
float cpu = 0;
int cnt = 0; // process count
Expand Down
2 changes: 2 additions & 0 deletions src/firemon/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void tree(pid_t pid) {
// print processes
int i;
for (i = 0; i < max_pids; i++) {
if (i == skip_process)
continue;
if (pids[i].level == 1)
pid_print_tree(i, 0, arg_nowrap);
}
Expand Down

0 comments on commit 2a0fb5c

Please sign in to comment.