On Wed, Feb 02, 2022 at 10:00:25PM -0800, Stephen Hemminger wrote:
> Systemd.exec supports configuring the runtime directory of a service
> via RuntimeDirectory=. This creates the directory with the necessary
> permissions which actual service may not have if running in container.
> 
> The change to DPDK is to look for the environment RUNTIME_DIRECTORY
> first and use that in preference to the fallback alternatives.
> 
> Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
> Acked-by: Bruce Richardson <bruce.richard...@intel.com>
> Reviewed-by: Morten Brørup <m...@smartsharesystems.com>
> ---
>  lib/eal/linux/eal.c         | 23 +++++++++++++----------
>  usertools/dpdk-telemetry.py |  9 +++++++--
>  2 files changed, 20 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
> index f2551c64b10c..8a5723f3b3a7 100644
> --- a/lib/eal/linux/eal.c
> +++ b/lib/eal/linux/eal.c
> @@ -86,25 +86,28 @@ struct lcore_config lcore_config[RTE_MAX_LCORE];
>  /* used by rte_rdtsc() */
>  int rte_cycles_vmware_tsc_map;
>  
> -static const char *default_runtime_dir = "/var/run";
> -
>  int
>  eal_create_runtime_dir(void)
>  {
> -     const char *directory = default_runtime_dir;
> -     const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
> -     const char *fallback = "/tmp";
> +     const char *directory;
>       char run_dir[PATH_MAX];
>       char tmp[PATH_MAX];
>       int ret;
>  
> -     if (getuid() != 0) {
> -             /* try XDG path first, fall back to /tmp */
> -             if (xdg_runtime_dir != NULL)
> -                     directory = xdg_runtime_dir;
> +     /* from RuntimeDirectory= see systemd.exec */
> +     directory = getenv("RUNTIME_DIRECTORY");
> +     if (directory == NULL) {
> +             /*
> +              * Used standard convention defined in
> +              * XDG Base Directory Specification and
> +              * Filesystem Hierachy Standard.
> +              */
> +             if (getuid() == 0)
> +                     directory = "/var/run";
>               else
> -                     directory = fallback;
> +                     directory = getenv("XDG_RUNTIME_DIR") ? : "/tmp";
>       }
> +
>       /* create DPDK subdirectory under runtime dir */
>       ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
>       if (ret < 0 || ret == sizeof(tmp)) {
> diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
> index 5b3bf83356c3..a49f0e76d07b 100755
> --- a/usertools/dpdk-telemetry.py
> +++ b/usertools/dpdk-telemetry.py
> @@ -75,9 +75,14 @@ def print_socket_options(prefix, paths):
>  def get_dpdk_runtime_dir(fp):
>      """ Using the same logic as in DPDK's EAL, get the DPDK runtime directory
>      based on the file-prefix and user """
> +    run_dir = os.environ.get('RUNTIME_DIRECTORY')
> +    if run_dir:
> +        return run_dir

This bit doesn't seem to match the EAL changes above, since in the EAL code
you are still appending the "dpdk" suffixes to the value returned from
RUNTIME_DIRECTORY.

>      if (os.getuid() == 0):
> -        return os.path.join('/var/run/dpdk', fp)
> -    return os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'dpdk', 
> fp)
> +        run_dir = '/var/run'
> +    else:
> +        run_dir = os.environ.get('XDG_RUNTIME_DIR', '/tmp'))
> +    return os.path.join(run_dir, 'dpdk', fp)
>  
>  
>  def list_fp():
> -- 
> 2.34.1
> 

Reply via email to