summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSongtao Zhan <zhanst1@chinatelecom.cn>2023-04-04 11:16:35 +0800
committerIlya Maximets <i.maximets@ovn.org>2023-04-06 22:48:41 +0200
commit771c989a9a957b2e487c9312eaee3bfb87638be5 (patch)
tree452046f7119c9e0e781a9c8b70a568001d2c42f4
parent8ac6375cac5bc9ececb6fcd8dccf62b1e4e65f49 (diff)
downloadopenvswitch-771c989a9a957b2e487c9312eaee3bfb87638be5.tar.gz
ovs-tcpdump: Stdout is shutdown before ovs-tcpdump exit.
If there is a pipe behind ovs-tcpdump (such as ovs-tcpdump -i eth0 | grep "192.168.1.1"), the child process (grep "192.168.1.1") may exit first and close the pipe when received SIGTERM. When farther process (ovs-tcpdump) exit, stdout is flushed into broken pipe, and then received a exception IOError. To avoid such problems, ovs-tcpdump first close stdout before exit. Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rwxr-xr-xutilities/ovs-tcpdump.in11
1 files changed, 11 insertions, 0 deletions
diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index a49ec9f94..420c11eb8 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -538,6 +538,17 @@ def main():
print(data.decode('utf-8'))
raise KeyboardInterrupt
except KeyboardInterrupt:
+ # If there is a pipe behind ovs-tcpdump (such as ovs-tcpdump
+ # -i eth0 | grep "192.168.1.1"), the pipe is no longer available
+ # after received Ctrl+C.
+ # If we write data to an unavailable pipe, a pipe error will be
+ # reported, so we turn off stdout to avoid subsequent flushing
+ # of data into the pipe.
+ try:
+ sys.stdout.close()
+ except IOError:
+ pass
+
if pipes.poll() is None:
pipes.terminate()