RE: [PATCH v10 2/9] test: add new function to get current file-prefix arg

Marat Khalili
2026-01-02T12:50:20Z

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Monday 29 December 2025 21:59
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>
> Subject: [PATCH v10 2/9] test: add new function to get current file-prefix arg
>
> Refactor so that there is one function to get current argument
> for "--file-prefix=XXX".
>
> The code does not need to initialize all these 4K buffers since
> they are directly used by functions that set them.
> The maximum sizeof of the current DPDK prefix is NAME_MAX (128)
> not PATH_MAX(4096) so save a significant amount of space.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> app/test/process.h | 38 ++++++++++++++++++++++++++++++++------
> 1 file changed, 32 insertions(+), 6 deletions(-)
>
> diff --git a/app/test/process.h b/app/test/process.h
> index f948a89786..251262d948 100644
> --- a/app/test/process.h
> +++ b/app/test/process.h
> @@ -199,15 +199,22 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
> return status;
> }
>
> -/* FreeBSD doesn't support file prefixes, so force compile failures for any
> - * tests attempting to use this function on FreeBSD.
> - */
> +/* FreeBSD doesn't support file prefixes, so no argument passed. */
> +#ifdef RTE_EXEC_ENV_FREEBSD
> +static inline const char *
> +file_prefix_arg(void)
> +{
> + /* BSD target doesn't support prefixes at this point */
> + return "";
> +}
> +#else
> +
> #ifdef RTE_EXEC_ENV_LINUX
> static inline char *
> get_current_prefix(char *prefix, int size)
> {
> - char path[PATH_MAX] = {0};
> - char buf[PATH_MAX] = {0};
> + char path[64];
> + char buf[PATH_MAX];
>
> /* get file for config (fd is always 3) */
> snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);

I wonder if we ever learn what stood behind this.

> @@ -216,10 +223,29 @@ get_current_prefix(char *prefix, int size)
> if (readlink(path, buf, sizeof(buf)) == -1)
> return NULL;
>
> - /* get the prefix */
> + /*
> + * path should be something like "/var/run/dpdk/config"

JFYI it's /run/dpdk/my-prefix/config on my system, although example correctly demonstrates the algorithm.

> + * which results in prefix of "dpdk"
> + */
> rte_basename(dirname(buf), prefix, size);
> + return prefix;
> +}
> +
> +/* Return a --file-prefix=XXXX argument or NULL */
> +static inline const char *
> +file_prefix_arg(void)
> +{
> + static char prefix[NAME_MAX + sizeof("--file-prefix=")];
> + char tmp[NAME_MAX];

Can current prefix change? Can we verify that it is filled already and return immediately?

>
> + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
> + fprintf(stderr, "Error - unable to get current prefix!\n");
> + return NULL;
> + }
> +
> + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
> return prefix;
> +#endif
> }
> #endif
>
> --
> 2.51.0

Considering the refactor in the next commit, with or without suggested optimization,

Acked-by: Marat Khalili <marat.khalili@huawei.com>