trace-cmd library: Use the new flow when creating output handler
PATCH v2 8/10 trace-cmd library: Use the new flow when creating output handler
The trace-cmd library APIs, that create a new output handler to a trace file, are converted to use the newly introduced APIs. Affected are:
tracecmd_create_file_latency()
tracecmd_create_init_fd()
tracecmd_create_init_file()
tracecmd_copy()
Signed-off-by Tzvetomir Stoyanov (VMware) <[email protected]>
--- lib/trace-cmd/trace-output.c | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-)
lib/trace-cmd/trace-output.c +48 -6
@@ -1503,11 +1503,19 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in {struct tracecmd_output *handle;char *path; +int fd; - handle =create_file (output_file,NULL ,NULL ,NULL , &all_event_list); -if (!handle) + fd =open (output_file,O_RDWR |O_CREAT |O_TRUNC |O_LARGEFILE ,0644 ); +if (fd <0 )return NULL ; + handle =tracecmd_output_allocate (fd); +if (!handle) + goto out_free; +if (tracecmd_output_write_init (handle)) + goto out_free; +if (tracecmd_output_write_headers (handle,NULL )) + goto out_free;/* * Save the command lines; */
@@ -1801,7 +1809,20 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd)struct tracecmd_output *tracecmd_create_init_fd (int fd) { -return create_file_fd (fd,NULL ,NULL ,NULL , &all_event_list,NULL ); +struct tracecmd_output *out; + + out =tracecmd_output_allocate (fd); +if (!out) +return NULL ; +if (tracecmd_output_write_init (out)) + goto error; +if (tracecmd_output_write_headers (out,NULL )) + goto error; + +return out; +error: +tracecmd_output_close (out); +return NULL ; } struct tracecmd_output *
@@ -1826,7 +1847,20 @@ tracecmd_create_init_file_glob(const char *output_file,struct tracecmd_output *tracecmd_create_init_file (const char *output_file) { -return create_file (output_file,NULL ,NULL ,NULL , &all_event_list); +struct tracecmd_output *handle; +int fd; + + fd =open (output_file,O_RDWR |O_CREAT |O_TRUNC |O_LARGEFILE ,0644 ); +if (fd <0 ) +return NULL ; + handle =tracecmd_create_init_fd (fd); +if (!handle) { +close (fd); +unlink (output_file); +return NULL ; + } + +return handle; } struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file,
@@ -1849,11 +1883,19 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file) {struct tracecmd_output *handle; +int fd; - handle =create_file (file, ihandle,NULL ,NULL , &all_event_list); -if (!handle) + fd =open (file,O_RDWR |O_CREAT |O_TRUNC |O_LARGEFILE ,0644 ); +if (fd <0 )return NULL ; + handle =tracecmd_output_allocate (fd); +if (!handle) + goto out_free; +if (tracecmd_output_set_from_input (handle, ihandle)) + goto out_free; +tracecmd_output_write_init (handle); +if (tracecmd_copy_headers (ihandle, handle->fd,0 ,0 ) <0 ) goto out_free;
Signature · 1 line
2.33.1