diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-02-25 16:28:45 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-02-25 16:28:45 -0500 |
commit | 8d1e65fdb15da0b0061cdb43c938e0882757648a (patch) | |
tree | 26dca82957cd9c7bb8fe1f42f1d8a3cd11254eab | |
parent | 014d7516b0129b0bf308bf0f898405f439aeeff9 (diff) |
trace-cmd: Have writing options to file be endian aware
It is possible that the options written to file is not the
same endian as the host endian. Have the options size and
id converted first.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-output.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/trace-output.c b/trace-output.c index 46afe48..194446b 100644 --- a/trace-output.c +++ b/trace-output.c | |||
@@ -80,6 +80,14 @@ do_write_check(struct tracecmd_output *handle, void *data, int size) | |||
80 | return __do_write_check(handle->fd, data, size); | 80 | return __do_write_check(handle->fd, data, size); |
81 | } | 81 | } |
82 | 82 | ||
83 | static short convert_endian_2(struct tracecmd_output *handle, short val) | ||
84 | { | ||
85 | if (!handle->pevent) | ||
86 | return val; | ||
87 | |||
88 | return __data2host2(handle->pevent, val); | ||
89 | } | ||
90 | |||
83 | static int convert_endian_4(struct tracecmd_output *handle, int val) | 91 | static int convert_endian_4(struct tracecmd_output *handle, int val) |
84 | { | 92 | { |
85 | if (!handle->pevent) | 93 | if (!handle->pevent) |
@@ -857,6 +865,8 @@ int tracecmd_add_option(struct tracecmd_output *handle, | |||
857 | static int add_options(struct tracecmd_output *handle) | 865 | static int add_options(struct tracecmd_output *handle) |
858 | { | 866 | { |
859 | unsigned short option; | 867 | unsigned short option; |
868 | unsigned short endian2; | ||
869 | unsigned int endian4; | ||
860 | int i; | 870 | int i; |
861 | 871 | ||
862 | if (handle->options_written) | 872 | if (handle->options_written) |
@@ -866,10 +876,12 @@ static int add_options(struct tracecmd_output *handle) | |||
866 | return -1; | 876 | return -1; |
867 | 877 | ||
868 | for (i = 0; i < handle->nr_options; i++) { | 878 | for (i = 0; i < handle->nr_options; i++) { |
869 | if (do_write_check(handle, &handle->options[i].id, 2)) | 879 | endian2 = convert_endian_2(handle, handle->options[i].id); |
880 | if (do_write_check(handle, &endian2, 2)) | ||
870 | return -1; | 881 | return -1; |
871 | 882 | ||
872 | if (do_write_check(handle, &handle->options[i].size, 4)) | 883 | endian4 = convert_endian_4(handle, handle->options[i].size); |
884 | if (do_write_check(handle, &endian4, 4)) | ||
873 | return -1; | 885 | return -1; |
874 | 886 | ||
875 | if (do_write_check(handle, handle->options[i].data, | 887 | if (do_write_check(handle, handle->options[i].data, |