linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Subject: [PATCH 5/8] trace-cmd: Move the input state updates into the functions that change the state
Date: Mon, 01 Mar 2021 09:37:29 -0500	[thread overview]
Message-ID: <20210301143857.396768544@goodmis.org> (raw)
In-Reply-To: 20210301143724.540985351@goodmis.org

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

It makes more sense to have the functions that change the state of the
descriptor to change the value that stores the state. This makes it more
robust in case these functions are called by something other than
tracecmd_read_headers(). That way the state changes with the update, and this
removes the dependency on create_file_fd with the state changes.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 9e1a44540201..9a4b1f4e118a 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -395,6 +395,8 @@ static int read_header_files(struct tracecmd_input *handle)
 	handle->ftrace_files_start =
 		lseek64(handle->fd, 0, SEEK_CUR);
 
+	handle->file_state = TRACECMD_FILE_HEADERS;
+
 	return 0;
 
  failed_read:
@@ -596,6 +598,8 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
 		regfree(ereg);
 	}
 
+	handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
+
 	return 0;
 }
 
@@ -678,6 +682,8 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)
 		regfree(ereg);
 	}
 
+	handle->file_state = TRACECMD_FILE_ALL_EVENTS;
+
 	return 0;
 
  failed:
@@ -713,6 +719,9 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)
 	tracecmd_parse_proc_kallsyms(pevent, buf, size);
 
 	free(buf);
+
+	handle->file_state = TRACECMD_FILE_KALLSYMS;
+
 	return 0;
 }
 
@@ -740,6 +749,8 @@ static int read_ftrace_printk(struct tracecmd_input *handle)
 
 	free(buf);
 
+	handle->file_state = TRACECMD_FILE_PRINTK;
+
 	return 0;
 }
 
@@ -791,32 +802,27 @@ int tracecmd_read_pre_headers(struct tracecmd_input *handle)
 	ret = read_header_files(handle);
 	if (ret < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_HEADERS;
+
 	tep_set_long_size(handle->pevent, handle->long_size);
 
 	ret = read_ftrace_files(handle, NULL);
 	if (ret < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
 
 	ret = read_event_files(handle, NULL);
 	if (ret < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_ALL_EVENTS;
 
 	ret = read_proc_kallsyms(handle);
 	if (ret < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_KALLSYMS;
 
 	ret = read_ftrace_printk(handle);
 	if (ret < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_PRINTK;
 
 	if (read_and_parse_cmdlines(handle) < 0)
 		return -1;
-	handle->file_state = TRACECMD_FILE_CMD_LINES;
 
 	return 0;
 }
@@ -2848,6 +2854,9 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)
 	cmdlines[size] = 0;
 	tracecmd_parse_cmdlines(pevent, cmdlines, size);
 	free(cmdlines);
+
+	handle->file_state = TRACECMD_FILE_CMD_LINES;
+
 	return 0;
 }
 
-- 
2.30.0



  parent reply	other threads:[~2021-03-01 14:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 14:37 [PATCH 0/8] trace-cmd: Fixes for trace-cmd restore Steven Rostedt
2021-03-01 14:37 ` [PATCH 1/8] trace-cmd restore: Fix to add saved cmdlines after calling tracecmd_create_init_file_override() Steven Rostedt
2021-03-01 14:37 ` [PATCH 2/8] trace-cmd: Create API tracecmd_read_pre_headers() Steven Rostedt
2021-03-02  4:49   ` Tzvetomir Stoyanov
2021-03-02 14:13     ` Steven Rostedt
2021-03-01 14:37 ` [PATCH 3/8] trace-cmd: Move tracecmd_write_cmdlines() out of tracecmd_append_cpu_data() Steven Rostedt
2021-03-01 14:37 ` [PATCH 4/8] trace-cmd: Move the output state updates into the functions that change the state Steven Rostedt
2021-03-01 14:37 ` Steven Rostedt [this message]
2021-03-01 14:37 ` [PATCH 6/8] trace-cmd output: Set file_state of output handle after copy of headers Steven Rostedt
2021-03-02  8:10   ` Tzvetomir Stoyanov
2021-03-02 14:19     ` Steven Rostedt
2021-03-02 14:51       ` Tzvetomir Stoyanov
2021-03-02 15:48         ` Steven Rostedt
2021-03-02 17:35           ` Tzvetomir Stoyanov
2021-03-02 19:59             ` Steven Rostedt
2021-03-02 14:22     ` Steven Rostedt
2021-03-01 14:37 ` [PATCH 7/8] trace-cmd input: Validate the input handle when copying from it Steven Rostedt
2021-03-01 14:37 ` [PATCH 8/8] trace-cmd input: Add validation updates to the copy of a handle Steven Rostedt

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=20210301143857.396768544@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@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).