From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 2/2] trace-cmd: Fix broken listener and add error checks
Date: Wed, 17 Feb 2021 06:23:41 +0200 [thread overview]
Message-ID: <20210217042341.1675546-3-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210217042341.1675546-1-tz.stoyanov@gmail.com>
The trace-cmd listener was broken by recent changes in writing saved
command lines in the trace file. There was no error checking in that
flow, so the trace-cmd listener indicates successful trace session,
even though the output trace file was broken.
Fixed the listener logic and added more error checks.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
tracecmd/trace-listen.c | 22 ++++++++++++++--------
tracecmd/trace-record.c | 31 ++++++++++++++++++++++++++-----
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index 7798fe4f..ecad7656 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -597,8 +597,12 @@ static int put_together_file(int cpus, int ofd, const char *node,
}
if (write_options) {
- tracecmd_write_cpus(handle, cpus);
- tracecmd_write_options(handle);
+ ret = tracecmd_write_cpus(handle, cpus);
+ if (ret)
+ goto out;
+ ret = tracecmd_write_options(handle);
+ if (ret)
+ goto out;
}
ret = tracecmd_write_cpu_data(handle, cpus, temp_files);
@@ -634,11 +638,12 @@ static int process_client(struct tracecmd_msg_handle *msg_handle,
stop_msg_handle = msg_handle;
/* Now we are ready to start reading data from the client */
- if (msg_handle->version == V3_PROTOCOL)
- tracecmd_msg_collect_data(msg_handle, ofd);
- else
+ if (msg_handle->version == V3_PROTOCOL) {
+ ret = tracecmd_msg_collect_data(msg_handle, ofd);
+ } else {
collect_metadata_from_client(msg_handle, ofd);
-
+ ret = 0;
+ }
stop_msg_handle = NULL;
/* wait a little to let our readers finish reading */
@@ -652,8 +657,9 @@ static int process_client(struct tracecmd_msg_handle *msg_handle,
/* wait a little to have the readers clean up */
sleep(1);
- ret = put_together_file(cpus, ofd, node, port,
- msg_handle->version < V3_PROTOCOL);
+ if (!ret)
+ ret = put_together_file(cpus, ofd, node, port,
+ msg_handle->version < V3_PROTOCOL);
destroy_all_readers(cpus, pid_array, node, port);
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 9396042d..f6131692 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3590,22 +3590,36 @@ static void add_options(struct tracecmd_output *handle, struct common_record_con
static struct tracecmd_msg_handle *
setup_connection(struct buffer_instance *instance, struct common_record_context *ctx)
{
- struct tracecmd_msg_handle *msg_handle;
- struct tracecmd_output *network_handle;
+ struct tracecmd_msg_handle *msg_handle = NULL;
+ struct tracecmd_output *network_handle = NULL;
+ int ret;
msg_handle = setup_network(instance);
/* Now create the handle through this socket */
if (msg_handle->version == V3_PROTOCOL) {
network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events);
+ if (!network_handle)
+ goto error;
tracecmd_set_quiet(network_handle, quiet);
add_options(network_handle, ctx);
- tracecmd_write_cpus(network_handle, instance->cpu_count);
- tracecmd_write_options(network_handle);
- tracecmd_msg_finish_sending_data(msg_handle);
+ ret = tracecmd_write_cmdlines(network_handle);
+ if (ret)
+ goto error;
+ ret = tracecmd_write_cpus(network_handle, instance->cpu_count);
+ if (ret)
+ goto error;
+ ret = tracecmd_write_options(network_handle);
+ if (ret)
+ goto error;
+ ret = tracecmd_msg_finish_sending_data(msg_handle);
+ if (ret)
+ goto error;
} else {
network_handle = tracecmd_create_init_fd_glob(msg_handle->fd,
listed_events);
+ if (!network_handle)
+ goto error;
tracecmd_set_quiet(network_handle, quiet);
}
@@ -3613,6 +3627,13 @@ setup_connection(struct buffer_instance *instance, struct common_record_context
/* OK, we are all set, let'r rip! */
return msg_handle;
+
+error:
+ if (msg_handle)
+ tracecmd_msg_handle_close(msg_handle);
+ if (network_handle)
+ tracecmd_output_close(network_handle);
+ return NULL;
}
static void finish_network(struct tracecmd_msg_handle *msg_handle)
--
2.29.2
next prev parent reply other threads:[~2021-02-17 4:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 4:23 [PATCH 0/2] Fix listener and add trace file validation Tzvetomir Stoyanov (VMware)
2021-02-17 4:23 ` [PATCH 1/2] trace-cmd: Add validation for reading and writing trace.dat files Tzvetomir Stoyanov (VMware)
2021-02-17 16:00 ` Steven Rostedt
2021-02-17 16:33 ` Tzvetomir Stoyanov
2021-02-17 18:27 ` Steven Rostedt
2021-02-18 3:49 ` Tzvetomir Stoyanov
2021-02-18 14:23 ` Steven Rostedt
2021-02-17 4:23 ` Tzvetomir Stoyanov (VMware) [this message]
2021-02-17 19:46 ` [PATCH 2/2] trace-cmd: Fix broken listener and add error checks 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=20210217042341.1675546-3-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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).