From patchwork Fri Sep 24 16:18:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 99642 X-Patchwork-Delegate: david.marchand@redhat.com 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 BFF18A0548; Fri, 24 Sep 2021 18:18:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B221A41305; Fri, 24 Sep 2021 18:18:53 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 71C34412F8; Fri, 24 Sep 2021 18:18:51 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10116"; a="287777195" X-IronPort-AV: E=Sophos;i="5.85,320,1624345200"; d="scan'208";a="287777195" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2021 09:18:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,320,1624345200"; d="scan'208";a="516081941" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga008.fm.intel.com with ESMTP; 24 Sep 2021 09:18:48 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, anatoly.burakov@intel.com, Bruce Richardson , stable@dpdk.org, David Marchand Date: Fri, 24 Sep 2021 17:18:42 +0100 Message-Id: <20210924161842.2879019-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210915141030.23514-1-bruce.richardson@intel.com> References: <20210915141030.23514-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] telemetry: fix "in-memory" process socket conflicts 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 Sender: "dev" When DPDK is run with --in-memory mode, multiple processes can run simultaneously using the same runtime dir. This leads to each process removing another process' telemetry socket as it started up, giving unexpected behaviour. This patch changes that behaviour to first check if the existing socket is active. If not, it's an old socket to be cleaned up and can be removed. If it is active, telemetry initialization fails and an error message is printed out giving instructions on how to remove the error; either by using file-prefix to have a different runtime dir (and therefore socket path) or by disabling telemetry if it not needed. Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality") Cc: stable@dpdk.org Reported-by: David Marchand Signed-off-by: Bruce Richardson Acked-by: Ciara Power --- v2: fix build error on FreeBSD --- lib/telemetry/telemetry.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 8304fbf6e9..78508c1a1d 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -457,15 +457,30 @@ create_socket(char *path) struct sockaddr_un sun = {.sun_family = AF_UNIX}; strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); - unlink(sun.sun_path); + if (bind(sock, (void *) &sun, sizeof(sun)) < 0) { struct stat st; - TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno)); - if (stat(socket_dir, &st) < 0 || !S_ISDIR(st.st_mode)) + /* first check if we have a runtime dir */ + if (stat(socket_dir, &st) < 0 || !S_ISDIR(st.st_mode)) { TMTY_LOG(ERR, "Cannot access DPDK runtime directory: %s\n", socket_dir); - sun.sun_path[0] = 0; - goto error; + goto error; + } + + /* check if current socket is active */ + if (connect(sock, (void *)&sun, sizeof(sun)) == 0) { + TMTY_LOG(ERR, "Error binding telemetry socket, path already in use\n"); + TMTY_LOG(ERR, "Use '--file-prefix' to select a different socket path, or '--no-telemetry' to disable\n"); + path[0] = 0; + goto error; + } + + /* socket is not active, delete and attempt rebind */ + unlink(sun.sun_path); + if (bind(sock, (void *) &sun, sizeof(sun)) < 0) { + TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno)); + goto error; + } } if (listen(sock, 1) < 0) {