From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>
Subject: [PATCH 07/13 v2] libtracefs: Add write_filter() helper function
Date: Mon, 29 Mar 2021 20:51:30 -0400 [thread overview]
Message-ID: <20210330005248.243416850@goodmis.org> (raw)
In-Reply-To: 20210330005123.151740983@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Wrap the writing of the filter into the filter file in a helper function
such that it can be used in more places.
Link: https://lore.kernel.org/linux-trace-devel/20210323013225.303716095@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
src/tracefs-tools.c | 58 ++++++++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 19 deletions(-)
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index db12f759be1b..470502b07f7d 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -461,6 +461,33 @@ static bool match(const char *str, struct func_filter *func_filter)
return regexec(&func_filter->re, str, 0, NULL, 0) == 0;
}
+/*
+ * Return 0 on success, -1 error writing, 1 on other errors.
+ */
+static int write_filter(int fd, const char *filter, const char *module)
+{
+ char *each_str = NULL;
+ int write_size;
+ int size;
+
+ if (module)
+ write_size = asprintf(&each_str, "%s:mod:%s ", filter, module);
+ else
+ write_size = asprintf(&each_str, "%s ", filter);
+
+ if (write_size < 0)
+ return 1;
+
+ size = write(fd, each_str, write_size);
+ free(each_str);
+
+ /* compare written bytes*/
+ if (size < write_size)
+ return -1;
+
+ return 0;
+}
+
static int check_available_filters(struct func_filter *func_filters,
const char *module, const char ***errs)
{
@@ -526,31 +553,24 @@ static int check_available_filters(struct func_filter *func_filters,
static int controlled_write(int fd, const char **filters,
const char *module, const char ***errs)
{
- char *each_str = NULL;
- int write_size = 0;
- int size = 0;
int ret = 0;
int i;
for (i = 0; filters[i]; i++) {
- if (module)
- write_size = asprintf(&each_str, "%s:mod:%s ", filters[i], module);
- else
- write_size = asprintf(&each_str, "%s ", filters[i]);
- if (write_size < 0) {
- ret = 1;
- goto error;
- }
- size = write(fd, each_str, write_size);
- /* compare written bytes*/
- if (size < write_size)
+ int r;
+
+ r = write_filter(fd, filters[i], module);
+ if (r < 0) {
add_errors(errs, filters[i], ret--);
- free(each_str);
- each_str = NULL;
+ } else if (r > 0) {
+ /* Not filter error */
+ if (errs) {
+ free(*errs);
+ *errs = NULL;
+ }
+ return 1;
+ }
}
- error:
- if (each_str)
- free(each_str);
return ret;
}
--
2.30.1
next prev parent reply other threads:[~2021-03-30 0:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 0:51 [PATCH 00/13 v2] libtracefs: Add tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 01/13 v2] libtracefs: An API to set the filtering of functions Steven Rostedt
2021-03-30 0:51 ` [PATCH 02/13 v2] libtracefs: Document function_filter API Steven Rostedt
2021-03-30 0:51 ` [PATCH 03/13 v2] libtracefs: Fix notations of tracefs_function_filter() and module parameter Steven Rostedt
2021-03-30 0:51 ` [PATCH 04/13 v2] libtracefs: Move opening of file out of controlled_write() Steven Rostedt
2021-03-30 0:51 ` [PATCH 05/13 v2] libtracefs: Add add_errors() helper function for control_write() Steven Rostedt
2021-03-30 0:51 ` [PATCH 06/13 v2] libtracefs: Add checking of available_filter_functions to tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` Steven Rostedt [this message]
2021-03-30 0:51 ` [PATCH 08/13 v2] libtracefs: Allow for setting filters with regex expressions Steven Rostedt
2021-04-01 16:33 ` sameeruddin shaik
2021-03-31 16:39 ` Steven Rostedt
2021-04-02 1:59 ` sameeruddin shaik
2021-04-01 2:41 ` Steven Rostedt
2021-03-30 0:51 ` [PATCH 09/13 v2] libtracefs: Add indexing to set functions in tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 10/13 v2] libtracefs: Pass in reset via flags to tracefs_function_filter() Steven Rostedt
2021-03-30 14:29 ` Tzvetomir Stoyanov
2021-03-30 14:53 ` Steven Rostedt
2021-03-30 0:51 ` [PATCH 11/13 v2] libtracefs: Add pthread_mutex_lock() around tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 12/13 v2] libtracefs: Move struct tracefs_instance to tracefs-local.h Steven Rostedt
2021-03-30 0:51 ` [PATCH 13/13 v2] libtracefs: Add CONTINUE to tracefs_function_filter() Steven Rostedt
2021-03-30 14:29 ` Tzvetomir Stoyanov
2021-03-30 14:52 ` Steven Rostedt
2021-03-30 15:14 ` Steven Rostedt
2021-03-30 15:32 ` Tzvetomir Stoyanov
2021-03-30 16:03 ` Steven Rostedt
2021-03-30 1:03 ` [RFC][PATCH 14/13 v2] libtracefs: Just past one filter in for tracefs_function_filter() Steven Rostedt
2021-03-30 14:31 ` Tzvetomir Stoyanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210330005248.243416850@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=sameeruddin.shaik8@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).