Merge lp:~bryce2/fatrace/filter_option into lp:fatrace

Proposed by Bryce Nesbitt
Status: Merged
Merged at revision: 62
Proposed branch: lp:~bryce2/fatrace/filter_option
Merge into: lp:fatrace
Diff against target: 94 lines (+36/-1)
1 file modified
fatrace.c (+36/-1)
To merge this branch: bzr merge lp:~bryce2/fatrace/filter_option
Reviewer Review Type Date Requested Status
Martin Pitt Approve
Bryce Nesbitt (community) Needs Resubmitting
Review via email: mp+251697@code.launchpad.net

Description of the change

New option:

-f MASK, --filter Show only the given event types (choose from C,R,O or W)

I use "-f W" to monitor writes, of which Google Chrome seems to be by far the worst culprit, especially if any tab has ever opened Youtube!

To post a comment you must log in.
lp:~bryce2/fatrace/filter_option updated
64. By Bryce Nesbitt <email address hidden>

Fix no flag case

Revision history for this message
Martin Pitt (pitti) wrote :

Very nice, thanks for this! I just see some minor issues below. I'll merge this once these get fixed.

review: Needs Fixing
lp:~bryce2/fatrace/filter_option updated
65. By Bryce Nesbitt <email address hidden>

fix a few style issues
make --filter case insensitive

Revision history for this message
Bryce Nesbitt (bryce2) wrote :

bzr commit
modified fatrace.c
Committed revision 65.

bzr push
Pushed up to revision 65.

review: Needs Resubmitting
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks! I added an error message for unknown options, documented the new version in the manpage, and fixed some style issues. I did a new upstream release https://launchpad.net/fatrace/trunk/0.10 with this, and will package this for Debian unstable now (from where it will flow into the next Ubuntu development series).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'fatrace.c'
2--- fatrace.c 2014-09-23 13:49:58 +0000
3+++ fatrace.c 2015-03-06 02:20:51 +0000
4@@ -34,6 +34,7 @@
5 #include <sys/stat.h>
6 #include <sys/fanotify.h>
7 #include <sys/time.h>
8+#include <ctype.h>
9
10 #define BUFSIZE 256*1024
11
12@@ -45,6 +46,7 @@
13
14 /* command line options */
15 static char* option_output = NULL;
16+static long option_filter_mask = 0xffffffff;
17 static long option_timeout = -1;
18 static int option_current_mount = 0;
19 static int option_timestamp = 0;
20@@ -97,6 +99,10 @@
21 static char pathname[PATH_MAX];
22 struct stat st;
23
24+ if ((data->mask & option_filter_mask) == 0) {
25+ return;
26+ }
27+
28 /* read process name */
29 snprintf (printbuf, sizeof (printbuf), "/proc/%i/comm", data->pid);
30 len = 0;
31@@ -212,6 +218,7 @@
32 " -s SECONDS, --seconds=SECONDS\tStop after the given number of seconds.\n"
33 " -t, --timestamp\t\tAdd timestamp to events. Give twice for seconds since the epoch.\n"
34 " -p PID, --ignore-pid PID\tIgnore events for this process ID. Can be specified multiple times.\n"
35+" -f MASK, --filter=MASK\tShow only the given event types (choose from C,R,O,or W).\n"
36 " -h, --help\t\t\tShow help.");
37 }
38
39@@ -224,6 +231,7 @@
40 parse_args (int argc, char** argv)
41 {
42 int c;
43+ int j;
44 long pid;
45 char *endptr;
46
47@@ -233,12 +241,13 @@
48 {"seconds", required_argument, 0, 's'},
49 {"timestamp", no_argument, 0, 't'},
50 {"ignore-pid", required_argument, 0, 'p'},
51+ {"filter", required_argument, 0, 'f'},
52 {"help", no_argument, 0, 'h'},
53 {0, 0, 0, 0 }
54 };
55
56 while (1) {
57- c = getopt_long (argc, argv, "co:s:tp:h", long_options, NULL);
58+ c = getopt_long (argc, argv, "co:s:tpf:h", long_options, NULL);
59
60 if (c == -1)
61 break;
62@@ -252,6 +261,32 @@
63 option_output = strdup (optarg);
64 break;
65
66+ case 'f':
67+ j = 0;
68+ option_filter_mask = 0x00000000;
69+ while(optarg[j] != '\0') {
70+ switch(toupper(optarg[j])) {
71+ case 'R':
72+ option_filter_mask |= FAN_ACCESS;
73+ break;
74+ case 'C':
75+ option_filter_mask |= FAN_CLOSE_WRITE;
76+ option_filter_mask |= FAN_CLOSE_NOWRITE;
77+ break;
78+ case 'W':
79+ option_filter_mask |= FAN_CLOSE_WRITE;
80+ option_filter_mask |= FAN_MODIFY;
81+ break;
82+ case 'O':
83+ option_filter_mask |= FAN_OPEN;
84+ break;
85+ default:
86+ ; /* ignore unkown values for backwards compatibility */
87+ }
88+ j++;
89+ }
90+ break;
91+
92 case 's':
93 option_timeout = strtol (optarg, &endptr, 10);
94 if (*endptr != '\0' || option_timeout <= 0) {

Subscribers

People subscribed via source and target branches