From patchwork Thu Feb 3 06:00:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 106827 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7EC14A00C2; Thu, 3 Feb 2022 07:00:35 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD39B426D3; Thu, 3 Feb 2022 07:00:30 +0100 (CET) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id B1F1E40151 for ; Thu, 3 Feb 2022 07:00:29 +0100 (CET) Received: by mail-pl1-f179.google.com with SMTP id s6so1262935plg.12 for ; Wed, 02 Feb 2022 22:00:29 -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=PHLenMHnTRoALcxfsl7UzLxwJZB8AkUkD/8mi8BPrak=; b=bD9GrqQHszChc/89uxXwK7aBqnM4/2c1aV1coJDEk+MziD4opJdiuU7GL1pjCuC9mK 2+f2I5u4bvLSscLeX/f4XpBxZUhHvENKo4fI634951q7/MOw4SIU6U+d+1lWaCK8ylG/ TMBa3xashTiDqh5wiGIcj8L1q4XF/Xge3Zaxxtj7NtdJJbsvhhyq6VNTEAJifHsWrwEp Nl7U+/40oHMylBwWm8L72hz2ja9s9XtiSbb6SQZ/kZhXptvrpznkms54pW6a2AqcpPza ia72T8+kLDAsMgeaqnieZRo9TJgqx63seRjo9hRujE2rV3QqIxa766xws8HX0yiQGOAB qOQw== 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=PHLenMHnTRoALcxfsl7UzLxwJZB8AkUkD/8mi8BPrak=; b=oe1f3/UqIdGI3w0PJC2CH414d9K6z/36nCOKuVVqOIqeKaucTR1wkU9QzSPLMV14Qc 1BnFzmPgu5Fid1XvJGfrgAMFXiLetwnnc9hE8n7XiXzxowP+yuMt/V0pPHvmbMMV2gG8 +JdDEU9i8OMXj6dIwihCLyNKLBnAZY2ZzHGYqVJLYgIfgO/5jMlQRDcacAzOqfdZNycA etFnnuO0C9qKZIZFWZk52Magdv3McAFZuiJZj1dzxUJR15bqyvgw8tI7GgW6WV3cibPG AuVdwoCvOTojEjy27rZFOfGgCEDWOKjQcerTFl8uCfKmu4zs/+HAZx+XJpu4nCsWXGIg ECqQ== X-Gm-Message-State: AOAM532bSyfUPDDckpWA+dGZ277jPNsR4E8b89Ae6hoMik3NB0GK89TE YSyaxHRTyK3qvLbIS444Rtr0F07Obkf5VwOe X-Google-Smtp-Source: ABdhPJzPDwQNMr4cKoLWLWMD9PyIMV4UcSmHXE5/RA5wCH3D+Y4kPcUVjWOXbFFGGVsUWNCUbYvWlA== X-Received: by 2002:a17:902:7e83:: with SMTP id z3mr30713541pla.122.1643868028673; Wed, 02 Feb 2022 22:00:28 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id h9sm28883504pfi.124.2022.02.02.22.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 22:00:28 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , talshn@mellanox.com, =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH 1/2] eal: remove size for eal_set_runtime_dir Date: Wed, 2 Feb 2022 22:00:24 -0800 Message-Id: <20220203060025.881552-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203060025.881552-1-stephen@networkplumber.org> References: <20211223233907.181033-1-stephen@networkplumber.org> <20220203060025.881552-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The size argument to eal_set_runtime_dir is useless and was being used incorrectly in strlcpy. It worked only because all callers passed PATH_MAX which is same as sizeof the destination runtime_dir. Note: this is an internal API so no user exposed change. Fixes: 57a2efb30477 ("eal: move OS common config objects") Cc: talshn@mellanox.com Signed-off-by: Stephen Hemminger Reviewed-by: Morten Brørup --- lib/eal/common/eal_common_config.c | 7 ++----- lib/eal/common/eal_private.h | 4 +--- lib/eal/freebsd/eal.c | 2 +- lib/eal/linux/eal.c | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/eal/common/eal_common_config.c b/lib/eal/common/eal_common_config.c index 1c4c4dd585d0..62a9d7a198db 100644 --- a/lib/eal/common/eal_common_config.c +++ b/lib/eal/common/eal_common_config.c @@ -29,12 +29,9 @@ rte_eal_get_runtime_dir(void) } int -eal_set_runtime_dir(char *run_dir, size_t size) +eal_set_runtime_dir(const char *run_dir) { - size_t str_size; - - str_size = strlcpy(runtime_dir, run_dir, size); - if (str_size >= size) { + if (strlcpy(runtime_dir, run_dir, PATH_MAX) >= PATH_MAX) { RTE_LOG(ERR, EAL, "Runtime directory string too long\n"); return -1; } diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 36bcc0b5a492..734f1f334b69 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -681,13 +681,11 @@ eal_mem_set_dump(void *virt, size_t size, bool dump); * * @param run_dir * The new runtime directory path of DPDK - * @param size - * The size of the new runtime directory path in bytes. * @return * 0 on success, (-1) on failure. */ int -eal_set_runtime_dir(char *run_dir, size_t size); +eal_set_runtime_dir(const char *run_dir); /** * Get the internal configuration structure. diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index a1cd2462db1b..503e276dc27f 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -123,7 +123,7 @@ eal_create_runtime_dir(void) return -1; } - if (eal_set_runtime_dir(run_dir, sizeof(run_dir))) + if (eal_set_runtime_dir(run_dir)) return -1; return 0; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 60b49248388e..f2551c64b10c 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -137,7 +137,7 @@ eal_create_runtime_dir(void) return -1; } - if (eal_set_runtime_dir(run_dir, sizeof(run_dir))) + if (eal_set_runtime_dir(run_dir)) return -1; return 0; From patchwork Thu Feb 3 06:00:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 106828 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DBC08A00C2; Thu, 3 Feb 2022 07:00:40 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D14F426D9; Thu, 3 Feb 2022 07:00:32 +0100 (CET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id B687141C3C for ; Thu, 3 Feb 2022 07:00:30 +0100 (CET) Received: by mail-pj1-f52.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so9077828pjq.0 for ; Wed, 02 Feb 2022 22:00:30 -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=pYUWeOdT3ny5sHcGv8ZGEcqGw3qHECpD1gm+e2C/sQg=; b=Vs1J0PMBBCoKjXcPwGN1aowjeWWwTQ+0UXrfmUrxWPGfo+2lrsT+FG90YRg0tlxyMG +otpygTu9yZPSx9N0pmfCZuI+R0S9/gCfooGtn8gEP/ROxIXaW1dyjRxU/BF/AXMb9rB EVqLlrl7QPtuHdOuYNWf6GlsCLz5gON/VHzjT/N8fhKsYa23XidZc1dc2l+80b18VTPD KakbG7EmiyUFcfJnfd5wrBzYxUnqe0Dbcpjiks8ZheH45jhQQH5vYJbuioWHaVhYD8M/ BYMQ3zg0aLq/HXwhgjrxw+qSNAlkKD5BPzPyJIOlCIrcMXnT96/xQL5lClaaoD75+mvZ SUnQ== 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=pYUWeOdT3ny5sHcGv8ZGEcqGw3qHECpD1gm+e2C/sQg=; b=7ugyxNd4n2wnZDadYTuPFBYgiispnhOkxE2WBg5sZpKud3T2A9HLqppFmkidGV+e/H O1pESZy5x7BdkFpJvVVJOLe+9Vb+CQ2nmkgMFOZowK10e4zQZ24vxzah1EgRC+L6GPgl bD0zvnK6RksnMWOcbHTDgcYYcpAjO0kX0JIzHUxFQ2DIn+rNWakvNgp0KQ6ExqLeYTO4 6+pVIXXDE532V3ty3t9igjslMI9xHfhjUlhTv/POJe4CtXeZ6QuNZttzJsmhO5E1t27b LG/I4EyvV8fZpaDVyPgz7J+4mZ5jcNe+8sPygN97UAYIIqkkwDjr3pAjFgzx/OH0o05J D2Cg== X-Gm-Message-State: AOAM530Us15vO1NhteTuxqRSJtSb1eK++ZlSIVe8OUHxGHNOTmUYu3W2 itBPIX49lhs2+Fs+MBp3yEOw7Is1XFCX/JZJ X-Google-Smtp-Source: ABdhPJx+8Dt13XDwLINjGX4QcawYVaxksd4yfweqJaB7OwjcUKdiaYZAGiZAx0LhU7G9vx/SMlw4Ew== X-Received: by 2002:a17:902:ecd0:: with SMTP id a16mr32845028plh.64.1643868029644; Wed, 02 Feb 2022 22:00:29 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id h9sm28883504pfi.124.2022.02.02.22.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 22:00:29 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH 2/2] eal: support systemd service convention for runtime directory Date: Wed, 2 Feb 2022 22:00:25 -0800 Message-Id: <20220203060025.881552-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203060025.881552-1-stephen@networkplumber.org> References: <20211223233907.181033-1-stephen@networkplumber.org> <20220203060025.881552-1-stephen@networkplumber.org> MIME-Version: 1.0 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 | 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 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():