DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
	"Bruce Richardson" <bruce.richardson@intel.com>,
	"Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH v2 2/2] eal: support systemd service convention for runtime directory
Date: Sat,  5 Feb 2022 09:11:01 -0800	[thread overview]
Message-ID: <20220205171101.7673-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20220205171101.7673-1-stephen@networkplumber.org>

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 <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/eal/linux/eal.c         | 23 +++++++++++++----------
 usertools/dpdk-telemetry.py | 10 +++++++---
 2 files changed, 20 insertions(+), 13 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..a81868a54789 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -75,9 +75,13 @@ 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 """
-    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 = os.environ.get('RUNTIME_DIRECTORY')
+    if not run_dir:
+        if (os.getuid() == 0):
+            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


  parent reply	other threads:[~2022-02-05 17:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 23:39 [RFC] " Stephen Hemminger
2021-12-26 12:20 ` Morten Brørup
2022-01-05 18:01   ` [RFC] eal: remove size for eal_set_runtime_dir Stephen Hemminger
2022-01-05 20:04     ` Morten Brørup
2022-01-07 12:07 ` [RFC] eal: support systemd service convention for runtime directory Bruce Richardson
2022-02-02 21:03   ` Thomas Monjalon
2022-02-02 21:07     ` Stephen Hemminger
2022-02-03  6:00 ` [PATCH 0/2] better support of configuring " Stephen Hemminger
2022-02-03  6:00   ` [PATCH 1/2] eal: remove size for eal_set_runtime_dir Stephen Hemminger
2022-02-03  6:00   ` [PATCH 2/2] eal: support systemd service convention for runtime directory Stephen Hemminger
2022-02-03 11:37     ` Bruce Richardson
2022-02-05 17:10   ` [PATCH v2 0/2] eal: support configuring " Stephen Hemminger
2022-02-05 17:11     ` [PATCH v2 1/2] eal: remove size for eal_set_runtime_dir Stephen Hemminger
2022-02-05 17:11     ` Stephen Hemminger [this message]
2022-02-08  4:43     ` [PATCH v2 0/2] eal: support configuring runtime directory Stephen Hemminger
2022-02-08 10:48       ` Bruce Richardson
2022-02-09  6:54 ` [PATCH v3 0/3] " Stephen Hemminger
2022-02-09  6:54   ` [PATCH v3 1/3] eal: remove size for eal_set_runtime_dir Stephen Hemminger
2022-02-09  6:54   ` [PATCH v3 2/3] eal: support systemd service convention for runtime directory Stephen Hemminger
2022-02-09  6:54   ` [PATCH v3 3/3] eal: move common filesystem setup code into one file Stephen Hemminger
2022-02-09  9:18     ` Bruce Richardson
2022-02-09 18:14   ` [PATCH v3 0/3] eal: support configuring runtime directory Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220205171101.7673-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).