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 D69F2A0C43; Fri, 8 Oct 2021 19:19:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 86DC1410DB; Fri, 8 Oct 2021 19:19:17 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id E27934067E for ; Fri, 8 Oct 2021 19:19:12 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10131"; a="207362120" X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="207362120" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 10:19:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="523050400" Received: from silpixa00399126.ir.intel.com ([10.237.223.151]) by orsmga001.jf.intel.com with ESMTP; 08 Oct 2021 10:19:04 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Ciara Power , David Marchand , Anatoly Burakov , Kevin Traynor , Bruce Richardson , Conor Walsh Date: Fri, 8 Oct 2021 18:18:49 +0100 Message-Id: <20211008171852.736387-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211008171852.736387-1-bruce.richardson@intel.com> References: <20210915141030.23514-1-bruce.richardson@intel.com> <20211008171852.736387-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v7 2/5] telemetry: fix deletion of active sockets 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, as it starts up, removing the telemetry socket of another process, 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") Reported-by: David Marchand Signed-off-by: Bruce Richardson Acked-by: Ciara Power Tested-by: Conor Walsh --- lib/telemetry/telemetry.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 48f4c7ba46..5d38e90bcc 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -457,27 +457,47 @@ 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); + TMTY_LOG(DEBUG, "Attempting socket bind to path '%s'\n", 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)) + TMTY_LOG(DEBUG, "Initial bind to socket '%s' failed.\n", path); + + /* 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"); + goto error; + } + + /* socket is not active, delete and attempt rebind */ + TMTY_LOG(DEBUG, "Attempting unlink and retrying bind\n"); + 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) { TMTY_LOG(ERR, "Error calling listen for socket: %s\n", strerror(errno)); + unlink(sun.sun_path); goto error; } + TMTY_LOG(DEBUG, "Socket creation and binding ok\n"); return sock; error: close(sock); - unlink_sockets(); + path[0] = 0; return -1; } -- 2.30.2