Message ID | 202304041116351906161@chinatelecom.cn |
---|---|
State | Accepted |
Commit | 8cba7a76d55c4e01f8cb394fb99063adb1b77dce |
Headers | show |
Series | [ovs-dev,v3] ovs-tcpdump: Stdout is shutdown before ovs-tcpdump exit | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | success | test: success |
On 4/4/23 05:16, Songtao Zhan wrote: > > To: dev@openvswitch.org, > i.maximets@ovn.org > > 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-tcp > dump first close stdout before exit. > > Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn> > --- Thanks! Applied and backported down to 2.17. Best regards, Ilya Maximets.
diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in index a49ec9f94..270207d01 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 subsequence flushing + # of data into the pipe. + try: + sys.stdout.close() + except IOError: + pass + if pipes.poll() is None: pipes.terminate()
To: dev@openvswitch.org, i.maximets@ovn.org 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-tcp dump first close stdout before exit. Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn> --- utilities/ovs-tcpdump.in | 11 +++++++++++ 1 file changed, 11 insertions(+)