From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BCBE9A0352; Sat, 5 Feb 2022 18:11:17 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8850D410E0; Sat, 5 Feb 2022 18:11:10 +0100 (CET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id 025CB40E25 for ; Sat, 5 Feb 2022 18:11:06 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id u130so7910154pfc.2 for ; Sat, 05 Feb 2022 09:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NVORtbdzLJHwK9BaiZe1EblAv+QytNKG/ICP4CHF5R0=; b=Q9UZj1FBHJAVesTzTeGWZkDYZ/MMGhjpKuPgh20rdV7lXKsZ9Vu3zXd70zQGOnf0PP pM5T9QM1zCinG542skTG0mx97FdpzIN1F7GWa90HJT+2jEJByD0BOmDDd606oIJtefN1 KwT//pLG/Tvpw/72oW2NjmzKgUeZVZrBiHbFrNkSqRbOJ3Dk1F/mubVjyvqoAX0Xr7qG FuQGQBbexAp0a/HUmi+E6VqkKnC/8sZv1/VdZslqACtKcye5n83jM0VaSzEYlWjXUXpl zdAq7lHmquQMd9VDC+PeR3UP3EoR2a7uzjhsfC9RR+xe3yV7cFKVEMDa3SixLwjlISP5 +yIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NVORtbdzLJHwK9BaiZe1EblAv+QytNKG/ICP4CHF5R0=; b=x5ZteuKAGoJglsQTW8EL1DeqzbhI6Rsk9yFft+VMSqCbkYqTAAwAcE/qB5Cf2hEvG9 nDoYH99jFw4c1cgc5e6LvPPZu7/9LXsmaNdFeYAmCuHXe6Zcjo8jevNPsg2UcGBTNX9Z jaE26erHCPHWcA5KfId9T2Dt3wlJq4Orn8LaJiKDeLn5GN4PqUOCWfK5+Nliq1Wu+YkE eoMKR+y+o84AbowcDEzS/y2CwalC5JSBZ0YCEVG/uX9uudDV2IMPcFJTtyQYQogJh+xL uXbq38JXf+8X7/c0LKrohEAyQLViL6PeJ0WAV2pP9M3/9YGxL8nPQUBACCTwW0jzhAQc 2h9g== X-Gm-Message-State: AOAM531cEXWiXbm2JqHAvvs2+97lWd42nC6+Q7kSJ65VN7iAUELADPkg PFjK2SAKzkWWx0Rj/oICgp+DirmMsN2ZAphA X-Google-Smtp-Source: ABdhPJyzl9IOvPdxkcDTNSuY9m7147gxAFLKLQfNZmw2Cl+8eXBMXmWm4u/TWiqHLAtGSlToJRkUTg== X-Received: by 2002:a65:414a:: with SMTP id x10mr3496926pgp.125.1644081065919; Sat, 05 Feb 2022 09:11:05 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id b13sm6600906pfm.27.2022.02.05.09.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Feb 2022 09:11:05 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v2 2/2] eal: support systemd service convention for runtime directory Date: Sat, 5 Feb 2022 09:11:01 -0800 Message-Id: <20220205171101.7673-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220205171101.7673-1-stephen@networkplumber.org> References: <20220203060025.881552-1-stephen@networkplumber.org> <20220205171101.7673-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.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 Acked-by: Bruce Richardson Reviewed-by: Morten Brørup --- 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