diff mbox

[ovs-dev,2/2] utilities/ovs-tcpdump.in: Poll the process status

Message ID 1467406781-1964-3-git-send-email-aconole@redhat.com
State Accepted
Headers show

Commit Message

Aaron Conole July 1, 2016, 8:59 p.m. UTC
From: Aaron Conole <aconole@bytheb.org>

Some options (such as -c X), when passed to tcpdump will cause it to
halt.  When this occurs, ovs-tcpdump will not recognize that such
an event has happened, and will spew newlines across the screen
running forever.  To fix this, ovs-tcpdump can poll and then raise a
KeyboardInterrupt event.

Now, when the underlying dump-cmd (such as tcpdump, tshark, etc.)
actually signals exit, ovs-tcpdump follows the SIGINT path, telling the
database to clean up.  Exit is signalled by either returning, 'killing',
or closing the output descriptor.

Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 utilities/ovs-tcpdump.in | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index 577f461..b29e691 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -425,11 +425,15 @@  def main():
 
     pipes = _doexec(*([dump_cmd, '-i', mirror_interface] + tcpdargs))
     try:
-        while True:
-            print(pipes.stdout.readline())
+        while pipes.poll() is None:
+            data = pipes.stdout.readline()
+            if len(data) == 0:
+                raise KeyboardInterrupt
+            print(data)
             if select.select([sys.stdin], [], [], 0.0)[0]:
                 data_in = sys.stdin.read()
                 pipes.stdin.write(data_in)
+        raise KeyboardInterrupt
     except KeyboardInterrupt:
         pipes.terminate()
         ovsdb.destroy_mirror('m%s' % interface, ovsdb.port_bridge(interface))