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

Aaron Conole aconole at redhat.com
Fri Jul 1 20:59:41 UTC 2016


From: Aaron Conole <aconole at 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 at redhat.com>
---
 utilities/ovs-tcpdump.in | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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))
-- 
2.5.5




More information about the dev mailing list