DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: ciara.power@intel.com, david.hunt@intel.com,
	Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org, Keith Wiles <keith.wiles@intel.com>
Subject: [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe
Date: Mon, 13 Sep 2021 11:51:36 +0100	[thread overview]
Message-ID: <20210913105137.130097-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com>

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 <bruce.richardson@intel.com>
---
 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):
-- 
2.30.2


  parent reply	other threads:[~2021-09-13 10:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors Bruce Richardson
2021-09-15 10:05   ` Kevin Laatz
2021-09-13 10:51 ` Bruce Richardson [this message]
2021-09-13 10:51 ` [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes Bruce Richardson
2021-09-15 10:46 ` [dpdk-dev] [PATCH 0/3] improvements for telemetry script Power, Ciara
2021-10-01 15:34   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210913105137.130097-3-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=ciara.power@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=keith.wiles@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).