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:42 +0200
commitb6686be9d4de1df1b7a04b1598e8ff6f111c70d9 (patch)
tree8228c2fcd8c2541ddfcee96b35656b73c7450e9b
parent53f9c67031d3076b0595034c6a776b04aa6a7adf (diff)
downloadopenvswitch-b6686be9d4de1df1b7a04b1598e8ff6f111c70d9.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()