public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
* [PATCH] app/test: simplify getting the current file prefix
@ 2026-02-20 17:49 Bruce Richardson
  2026-02-23 11:21 ` Marat Khalili
  2026-02-25 16:20 ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Bruce Richardson
  0 siblings, 2 replies; 7+ messages in thread
From: Bruce Richardson @ 2026-02-20 17:49 UTC (permalink / raw)
  To: dev; +Cc: stephen, Bruce Richardson

Rather than opening particular fd's in the /proc directory, just use the
rte_eal_get_runtime_dir() function to derive the file-prefix in use.
Since the runtime dir call cannot return NULL, we can simplify/remove
the error handling where it's used.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/process.h | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/app/test/process.h b/app/test/process.h
index 402dc4f96f..1ab5671943 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -8,12 +8,11 @@
 #include <errno.h>  /* errno */
 #include <limits.h> /* PATH_MAX */
 #ifndef RTE_EXEC_ENV_WINDOWS
-#include <libgen.h> /* basename et al */
 #include <sys/wait.h>
 #endif
 #include <stdlib.h> /* NULL */
 #include <string.h> /* strerror */
-#include <unistd.h> /* readlink */
+#include <unistd.h>
 #include <dirent.h>
 
 #include <rte_string_fns.h> /* strlcpy */
@@ -239,17 +238,7 @@ file_prefix_arg(void)
 static inline char *
 get_current_prefix(char *prefix, int size)
 {
-	char buf[PATH_MAX];
-
-	/* get file for config (fd is always 3) return NULL on error */
-	if (readlink("/proc/self/fd/3", buf, sizeof(buf)) == -1)
-		return NULL;
-
-	/*
-	 * path should be something like "/var/run/dpdk/config"
-	 * which results in prefix of "dpdk"
-	 */
-	rte_basename(dirname(buf), prefix, size);
+	rte_basename(rte_eal_get_runtime_dir(), prefix, size);
 	return prefix;
 }
 
@@ -260,12 +249,8 @@ file_prefix_arg(void)
 	static char prefix[NAME_MAX + sizeof("--file-prefix=")];
 	char tmp[NAME_MAX];
 
-	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);
+	snprintf(prefix, sizeof(prefix), "--file-prefix=%s",
+			get_current_prefix(tmp, sizeof(tmp)));
 	return prefix;
 #endif
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH] app/test: simplify getting the current file prefix
  2026-02-20 17:49 [PATCH] app/test: simplify getting the current file prefix Bruce Richardson
@ 2026-02-23 11:21 ` Marat Khalili
  2026-02-23 16:56   ` Bruce Richardson
  2026-02-25 16:20 ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Bruce Richardson
  1 sibling, 1 reply; 7+ messages in thread
From: Marat Khalili @ 2026-02-23 11:21 UTC (permalink / raw)
  To: Bruce Richardson, dev@dpdk.org; +Cc: stephen@networkplumber.org

> diff --git a/app/test/process.h b/app/test/process.h
> index 402dc4f96f..1ab5671943 100644
> --- a/app/test/process.h
> +++ b/app/test/process.h
> @@ -8,12 +8,11 @@
>  #include <errno.h>  /* errno */
>  #include <limits.h> /* PATH_MAX */
>  #ifndef RTE_EXEC_ENV_WINDOWS
> -#include <libgen.h> /* basename et al */
>  #include <sys/wait.h>
>  #endif
>  #include <stdlib.h> /* NULL */
>  #include <string.h> /* strerror */
> -#include <unistd.h> /* readlink */
> +#include <unistd.h>

Can we delete it entirely? Compiles for me at least.

>  #include <dirent.h>
> 
>  #include <rte_string_fns.h> /* strlcpy */
> @@ -239,17 +238,7 @@ file_prefix_arg(void)
>  static inline char *
>  get_current_prefix(char *prefix, int size)
>  {
> -	char buf[PATH_MAX];
> -
> -	/* get file for config (fd is always 3) return NULL on error */
> -	if (readlink("/proc/self/fd/3", buf, sizeof(buf)) == -1)
> -		return NULL;
> -
> -	/*
> -	 * path should be something like "/var/run/dpdk/config"
> -	 * which results in prefix of "dpdk"
> -	 */
> -	rte_basename(dirname(buf), prefix, size);
> +	rte_basename(rte_eal_get_runtime_dir(), prefix, size);
>  	return prefix;

Do we even need it as a separate function anymore?

>  }
> 
> @@ -260,12 +249,8 @@ file_prefix_arg(void)
>  	static char prefix[NAME_MAX + sizeof("--file-prefix=")];
>  	char tmp[NAME_MAX];
> 
> -	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);
> +	snprintf(prefix, sizeof(prefix), "--file-prefix=%s",
> +			get_current_prefix(tmp, sizeof(tmp)));
>  	return prefix;
>  #endif
>  }
> --
> 2.51.0

With or without comments above addressed,
Acked-by: Marat Khalili <marat.khalili@huawei.com>

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] app/test: simplify getting the current file prefix
  2026-02-23 11:21 ` Marat Khalili
@ 2026-02-23 16:56   ` Bruce Richardson
  0 siblings, 0 replies; 7+ messages in thread
From: Bruce Richardson @ 2026-02-23 16:56 UTC (permalink / raw)
  To: Marat Khalili; +Cc: dev@dpdk.org, stephen@networkplumber.org

On Mon, Feb 23, 2026 at 11:21:30AM +0000, Marat Khalili wrote:
> > diff --git a/app/test/process.h b/app/test/process.h
> > index 402dc4f96f..1ab5671943 100644
> > --- a/app/test/process.h
> > +++ b/app/test/process.h
> > @@ -8,12 +8,11 @@
> >  #include <errno.h>  /* errno */
> >  #include <limits.h> /* PATH_MAX */
> >  #ifndef RTE_EXEC_ENV_WINDOWS
> > -#include <libgen.h> /* basename et al */
> >  #include <sys/wait.h>
> >  #endif
> >  #include <stdlib.h> /* NULL */
> >  #include <string.h> /* strerror */
> > -#include <unistd.h> /* readlink */
> > +#include <unistd.h>
> 
> Can we delete it entirely? Compiles for me at least.
> 

I believe there are still functions used from it, so I would keep it for
safety.

> >  #include <dirent.h>
> > 
> >  #include <rte_string_fns.h> /* strlcpy */
> > @@ -239,17 +238,7 @@ file_prefix_arg(void)
> >  static inline char *
> >  get_current_prefix(char *prefix, int size)
> >  {
> > -	char buf[PATH_MAX];
> > -
> > -	/* get file for config (fd is always 3) return NULL on error */
> > -	if (readlink("/proc/self/fd/3", buf, sizeof(buf)) == -1)
> > -		return NULL;
> > -
> > -	/*
> > -	 * path should be something like "/var/run/dpdk/config"
> > -	 * which results in prefix of "dpdk"
> > -	 */
> > -	rte_basename(dirname(buf), prefix, size);
> > +	rte_basename(rte_eal_get_runtime_dir(), prefix, size);
> >  	return prefix;
> 
> Do we even need it as a separate function anymore?
> 

This function is used in test_eal_flags.c, which is why it's left here as
separate function.

> >  }
> > 
> > @@ -260,12 +249,8 @@ file_prefix_arg(void)
> >  	static char prefix[NAME_MAX + sizeof("--file-prefix=")];
> >  	char tmp[NAME_MAX];
> > 
> > -	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);
> > +	snprintf(prefix, sizeof(prefix), "--file-prefix=%s",
> > +			get_current_prefix(tmp, sizeof(tmp)));
> >  	return prefix;
> >  #endif
> >  }
> > --
> > 2.51.0
> 
> With or without comments above addressed,
> Acked-by: Marat Khalili <marat.khalili@huawei.com>
> 
> Tested-by: Marat Khalili <marat.khalili@huawei.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses
  2026-02-20 17:49 [PATCH] app/test: simplify getting the current file prefix Bruce Richardson
  2026-02-23 11:21 ` Marat Khalili
@ 2026-02-25 16:20 ` Bruce Richardson
  2026-02-25 16:20   ` [PATCH v2 2/2] app/test: simplify getting the current file prefix Bruce Richardson
  2026-02-26 17:04   ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Marat Khalili
  1 sibling, 2 replies; 7+ messages in thread
From: Bruce Richardson @ 2026-02-25 16:20 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, stable

The #endif for the #ifdef Linux block to add the "get_current_prefix()"
and the "file_prefix_arg()" functions to process.h was on the wrong
line, leaving a stray "}" outside the block. Fix this and in the process
(no pun intended) simplify the #ifdefs to just a non-Linux and a Linux
block, removing one level of #ifdefs.

Fixes: f17b6eacf00a ("test: avoid file prefix overflow")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/process.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/app/test/process.h b/app/test/process.h
index 402dc4f96f..a21cdfd46d 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -225,17 +225,14 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
 	return status;
 }
 
-/* FreeBSD doesn't support file prefixes, so no argument passed. */
-#ifdef RTE_EXEC_ENV_FREEBSD
+/* Only Linux supports file prefixes. */
+#ifndef RTE_EXEC_ENV_LINUX
 static inline const char *
 file_prefix_arg(void)
 {
-	/* BSD target doesn't support prefixes at this point */
 	return "";
 }
-#else
-
-#ifdef RTE_EXEC_ENV_LINUX
+#else /* RTE_EXEC_ENV_LINUX */
 static inline char *
 get_current_prefix(char *prefix, int size)
 {
@@ -253,7 +250,7 @@ get_current_prefix(char *prefix, int size)
 	return prefix;
 }
 
-/* Return a --file-prefix=XXXX argument or NULL */
+/* Return a --file-prefix=XXXX argument */
 static inline const char *
 file_prefix_arg(void)
 {
@@ -267,8 +264,7 @@ file_prefix_arg(void)
 
 	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
 	return prefix;
-#endif
 }
-#endif
+#endif /* RTE_EXEC_ENV_LINUX */
 
 #endif /* _PROCESS_H_ */
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] app/test: simplify getting the current file prefix
  2026-02-25 16:20 ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Bruce Richardson
@ 2026-02-25 16:20   ` Bruce Richardson
  2026-03-05 16:35     ` David Marchand
  2026-02-26 17:04   ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Marat Khalili
  1 sibling, 1 reply; 7+ messages in thread
From: Bruce Richardson @ 2026-02-25 16:20 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, Marat Khalili

Rather than opening particular fd's in the /proc directory, just use the
rte_eal_get_runtime_dir() function to derive the file-prefix in use.
Since the runtime dir call cannot return NULL, we can simplify/remove
the error handling where it's used.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Marat Khalili <marat.khalili@huawei.com>
Tested-by: Marat Khalili <marat.khalili@huawei.com>
---
 app/test/process.h | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/app/test/process.h b/app/test/process.h
index a21cdfd46d..df43966a2a 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -8,12 +8,11 @@
 #include <errno.h>  /* errno */
 #include <limits.h> /* PATH_MAX */
 #ifndef RTE_EXEC_ENV_WINDOWS
-#include <libgen.h> /* basename et al */
 #include <sys/wait.h>
 #endif
 #include <stdlib.h> /* NULL */
 #include <string.h> /* strerror */
-#include <unistd.h> /* readlink */
+#include <unistd.h>
 #include <dirent.h>
 
 #include <rte_string_fns.h> /* strlcpy */
@@ -236,17 +235,7 @@ file_prefix_arg(void)
 static inline char *
 get_current_prefix(char *prefix, int size)
 {
-	char buf[PATH_MAX];
-
-	/* get file for config (fd is always 3) return NULL on error */
-	if (readlink("/proc/self/fd/3", buf, sizeof(buf)) == -1)
-		return NULL;
-
-	/*
-	 * path should be something like "/var/run/dpdk/config"
-	 * which results in prefix of "dpdk"
-	 */
-	rte_basename(dirname(buf), prefix, size);
+	rte_basename(rte_eal_get_runtime_dir(), prefix, size);
 	return prefix;
 }
 
@@ -257,12 +246,8 @@ file_prefix_arg(void)
 	static char prefix[NAME_MAX + sizeof("--file-prefix=")];
 	char tmp[NAME_MAX];
 
-	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);
+	snprintf(prefix, sizeof(prefix), "--file-prefix=%s",
+			get_current_prefix(tmp, sizeof(tmp)));
 	return prefix;
 }
 #endif /* RTE_EXEC_ENV_LINUX */
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses
  2026-02-25 16:20 ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Bruce Richardson
  2026-02-25 16:20   ` [PATCH v2 2/2] app/test: simplify getting the current file prefix Bruce Richardson
@ 2026-02-26 17:04   ` Marat Khalili
  1 sibling, 0 replies; 7+ messages in thread
From: Marat Khalili @ 2026-02-26 17:04 UTC (permalink / raw)
  To: Bruce Richardson, dev@dpdk.org; +Cc: stable@dpdk.org

> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Wednesday 25 February 2026 16:21
> To: dev@dpdk.org
> Cc: Bruce Richardson <bruce.richardson@intel.com>; stable@dpdk.org
> Subject: [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses
> 
> The #endif for the #ifdef Linux block to add the "get_current_prefix()"
> and the "file_prefix_arg()" functions to process.h was on the wrong
> line, leaving a stray "}" outside the block. Fix this and in the process
> (no pun intended) simplify the #ifdefs to just a non-Linux and a Linux
> block, removing one level of #ifdefs.
> 
> Fixes: f17b6eacf00a ("test: avoid file prefix overflow")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  app/test/process.h | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/app/test/process.h b/app/test/process.h
> index 402dc4f96f..a21cdfd46d 100644
> --- a/app/test/process.h
> +++ b/app/test/process.h
> @@ -225,17 +225,14 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
>  	return status;
>  }
> 
> -/* FreeBSD doesn't support file prefixes, so no argument passed. */
> -#ifdef RTE_EXEC_ENV_FREEBSD
> +/* Only Linux supports file prefixes. */
> +#ifndef RTE_EXEC_ENV_LINUX
>  static inline const char *
>  file_prefix_arg(void)
>  {
> -	/* BSD target doesn't support prefixes at this point */
>  	return "";
>  }
> -#else
> -
> -#ifdef RTE_EXEC_ENV_LINUX
> +#else /* RTE_EXEC_ENV_LINUX */
>  static inline char *
>  get_current_prefix(char *prefix, int size)
>  {
> @@ -253,7 +250,7 @@ get_current_prefix(char *prefix, int size)
>  	return prefix;
>  }
> 
> -/* Return a --file-prefix=XXXX argument or NULL */
> +/* Return a --file-prefix=XXXX argument */
>  static inline const char *
>  file_prefix_arg(void)
>  {
> @@ -267,8 +264,7 @@ file_prefix_arg(void)
> 
>  	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
>  	return prefix;
> -#endif
>  }
> -#endif
> +#endif /* RTE_EXEC_ENV_LINUX */
> 
>  #endif /* _PROCESS_H_ */
> --
> 2.51.0

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

Tested on Linux.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] app/test: simplify getting the current file prefix
  2026-02-25 16:20   ` [PATCH v2 2/2] app/test: simplify getting the current file prefix Bruce Richardson
@ 2026-03-05 16:35     ` David Marchand
  0 siblings, 0 replies; 7+ messages in thread
From: David Marchand @ 2026-03-05 16:35 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, Marat Khalili

On Wed, 25 Feb 2026 at 17:21, Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> Rather than opening particular fd's in the /proc directory, just use the
> rte_eal_get_runtime_dir() function to derive the file-prefix in use.
> Since the runtime dir call cannot return NULL, we can simplify/remove
> the error handling where it's used.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Marat Khalili <marat.khalili@huawei.com>
> Tested-by: Marat Khalili <marat.khalili@huawei.com>

Series applied, thanks Bruce.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-05 16:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-20 17:49 [PATCH] app/test: simplify getting the current file prefix Bruce Richardson
2026-02-23 11:21 ` Marat Khalili
2026-02-23 16:56   ` Bruce Richardson
2026-02-25 16:20 ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Bruce Richardson
2026-02-25 16:20   ` [PATCH v2 2/2] app/test: simplify getting the current file prefix Bruce Richardson
2026-03-05 16:35     ` David Marchand
2026-02-26 17:04   ` [PATCH v2 1/2] app/test: fix ifdefs in header for managing subprocesses Marat Khalili

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox