@@ -37,6 +37,12 @@ not a period, but will match any one character. To force a regular
expression, either prefix _filter_ with a '^' or append it with a '$' as
the _filter_ does complete matches of the functions anyway.
+The _filter_ may be NULL if a previous call to *tracefs_function_filter()* with
+the same _instance_ had *TRACEFS_FL_CONTINUE* set and this call does not. This is
+useful to simply commit the previous filters. It may also be NULL
+if *TRACEFS_FL_RESET* is set and the previous call did not have the same _instance_
+and *TRACEFS_FL_CONTINUE* set. This is useful to just clear the filter.
+
FLAGS
-----
@@ -102,20 +108,25 @@ int main(int argc, char *argv[])
{
struct tracefs_instance *inst = tracefs_instance_create(INST);
int ret;
- int reset = TRACEFS_FL_RESET;
int i;
if (!inst) {
/* Error creating new trace instance */
}
+ /* First reset the filter */
+ ret = tracefs_function_filter(inst, NULL, NULL,
+ TRACEFS_FL_RESET | TRACEFS_FL_CONTINUE);
+ if (ret) {
+ printf("Failed to reset the filter\n");
+ /* Make sure it is closed, -1 means filter was started */
+ if (ret < 0)
+ tracefs_function_filter(inst, NULL, NULL, 0);
+ }
+
for (i = 0; filters[i]; i++) {
- /*
- * Only the first call can have TRACEFS_FL_RESET set
- * while TRACEFS_FL_CONTINUE is set.
- */
ret = tracefs_function_filter(inst, filters[i], NULL,
- reset | TRACEFS_FL_CONTINUE);
+ TRACEFS_FL_CONTINUE);
if (ret) {
if (errno == EINVAL)
@@ -123,7 +134,6 @@ int main(int argc, char *argv[])
else
printf("Failed writing %s\n", filters[i]);
}
- reset = 0;
}
ret = tracefs_function_filter(inst, "*", "ext4", 0);
@@ -133,8 +143,9 @@ int main(int argc, char *argv[])
tracefs_function_filter(inst, NULL, NULL, 0);
}
+ out:
tracefs_instance_destroy(inst);
- return 0;
+ return ret;
}
--
@@ -794,6 +794,10 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
close(*fd);
*fd = -1;
}
+ /* Also OK to call if reset flag is set */
+ if (reset)
+ goto open_file;
+
goto out;
}
@@ -804,6 +808,7 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
if (ret)
goto out_free;
+ open_file:
ret = 1;
ftrace_filter_path = tracefs_instance_get_file(instance, TRACE_FILTER);
if (!ftrace_filter_path)
@@ -819,9 +824,13 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
errno = 0;
- ret = write_func_list(*fd, func_list);
- if (ret > 0)
- ret = controlled_write(*fd, &func_filter, module);
+ ret = 0;
+
+ if (filter) {
+ ret = write_func_list(*fd, func_list);
+ if (ret > 0)
+ ret = controlled_write(*fd, &func_filter, module);
+ }
if (!cont) {
close(*fd);