Re: [PATCH v2 4/7] trace-cmd split: Add functions to generate temp files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 22 Jan 2024 17:43:33 +0100
Pierre Gondois <pierre.gondois@xxxxxxx> wrote:

> To prepare handling of multiple instances and storing them
> in temporary files, add utility functions generating file names,
> removing files, creating files:
> - get_temp_file()
> - delete_temp_file()
> - put_temp_file()
> - touch_file()
> 
> Also make use these functions.
> 
> Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
> ---
>  tracecmd/trace-split.c | 70 +++++++++++++++++++++++++++++++++---------
>  1 file changed, 55 insertions(+), 15 deletions(-)
> 
> diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
> index f46813d1..5f3ed940 100644
> --- a/tracecmd/trace-split.c
> +++ b/tracecmd/trace-split.c
> @@ -392,6 +392,52 @@ static int parse_cpu(struct tracecmd_input *handle,
>  	return 0;
>  }
>  
> +static char *get_temp_file(const char *output_file, const char *name, int cpu)
> +{
> +	const char *dot;
> +	char *file = NULL;
> +	char *output;
> +	char *base;
> +	char *dir;
> +	int ret;
> +
> +	if (name)
> +		dot = ".";
> +	else
> +		dot = name = "";
> +
> +	output = strdup(output_file);

Nit on strdup() error checking again.

I know that I have forgotten to do this too, but lets not add more ;-)
and lets add the checks if they were missing when we modify that code.

Doing a clean up on that is on my todo list.

-- Steve


> +	/* Extract basename() first, as dirname() truncates output */
> +	base = basename(output);
> +	dir = dirname(output);
> +
> +	ret = asprintf(&file, "%s/.tmp.%s.%s%s%d", dir, base, name, dot, cpu);
> +	if (ret < 0)
> +		die("Failed to allocate file for %s %s %s %d", dir, base, name, cpu);
> +	free(output);
> +	return file;
> +}




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux