From patchwork Mon Sep 13 10:51:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 98740 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 8A33BA0C45; Mon, 13 Sep 2021 12:52:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0AA1410EB; Mon, 13 Sep 2021 12:52:12 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 6446C410E1; Mon, 13 Sep 2021 12:52:10 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10105"; a="208871221" X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="208871221" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 03:52:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="696639031" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga006.fm.intel.com with ESMTP; 13 Sep 2021 03:52:08 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, david.hunt@intel.com, Bruce Richardson , stable@dpdk.org, Keith Wiles Date: Mon, 13 Sep 2021 11:51:36 +0100 Message-Id: <20210913105137.130097-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com> References: <20210913105137.130097-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe 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" To allow the script to take queries from input pipes e.g. "echo /ethdev/stats,0 | dpdk-telemetry.py", we need to handle the case of EOF correctly without crashing with an exception. Do this by using a try-except block around the input handling. Fixes: 6a2967c112a3 ("usertools: add new telemetry script") Cc: stable@dpdk.org Signed-off-by: Bruce Richardson --- usertools/dpdk-telemetry.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index bdc617db18..7ebbb64fce 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -69,13 +69,17 @@ def handle_socket(path): CMDS = read_socket(sock, output_buf_len, False)["/"] # interactive prompt - text = input('--> ').strip() - while text != "quit": - if text.startswith('/'): - sock.send(text.encode()) - read_socket(sock, output_buf_len) + try: text = input('--> ').strip() - sock.close() + while text != "quit": + if text.startswith('/'): + sock.send(text.encode()) + read_socket(sock, output_buf_len) + text = input('--> ').strip() + except EOFError: + pass + finally: + sock.close() def readline_complete(text, state):