DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <sthemmin@microsoft.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH] eal: allow user to override DPDK runtime path
Date: Wed, 10 Mar 2021 09:21:37 -0800	[thread overview]
Message-ID: <20210310172137.59938-1-sthemmin@microsoft.com> (raw)

There can be cases such as containers or other runtime environments
where DPDK may not be able to access the default runtime path.
This patch introduces DPDK_RUNTIME_DIR as an environment variable
to allow controlling and overriding the path.

The example we have is DPDK application running in an untrusted
systemd container. In this case, it is not root, and XDG_RUNTIME_DIR
is not set (since it is not a user application), and /tmp is
blocked. The correct place for this application is to use /run.

In any case, hard coded path assumptions are a problem.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linux/eal.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 6c34ac890386..f2a5e73817d6 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -90,20 +90,26 @@ static const char *default_runtime_dir = "/var/run";
 int
 eal_create_runtime_dir(void)
 {
-	const char *directory = default_runtime_dir;
+	const char *directory;
 	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
 	const char *fallback = "/tmp";
 	char run_dir[PATH_MAX];
 	char tmp[PATH_MAX];
 	int ret;
 
-	if (getuid() != 0) {
+	directory = getenv("DPDK_RUNTIME_DIR");
+	if (directory != NULL) {
+		RTE_LOG(DEBUG, EAL, "Using DPDK runtime directory: %s\n", directory);
+	} else if (getuid() == 0) {
+		directory = default_runtime_dir;
+	} else {
 		/* try XDG path first, fall back to /tmp */
 		if (xdg_runtime_dir != NULL)
 			directory = xdg_runtime_dir;
 		else
 			directory = fallback;
 	}
+
 	/* create DPDK subdirectory under runtime dir */
 	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
 	if (ret < 0 || ret == sizeof(tmp)) {
-- 
2.30.1


             reply	other threads:[~2021-03-10 17:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 17:21 Stephen Hemminger [this message]
2021-03-10 17:27 ` Bruce Richardson
2021-03-10 18:33   ` Stephen Hemminger
2021-03-11 12:13     ` Bruce Richardson
2021-03-12 10:56       ` Burakov, Anatoly
2021-03-12 12:05         ` Bruce Richardson
2021-03-12 12:49           ` Burakov, Anatoly

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=20210310172137.59938-1-sthemmin@microsoft.com \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=sthemmin@microsoft.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).