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:43:23 +0200
commit8cba7a76d55c4e01f8cb394fb99063adb1b77dce (patch)
tree3f5d82a4ae06922634f1f5367465e768b811bb90
parent9d840923d32124fe427de76e8234c49d64e4bb77 (diff)
downloadopenvswitch-8cba7a76d55c4e01f8cb394fb99063adb1b77dce.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()