Skip to content

Commit

Permalink
ovs-tcpdump: Stdout is shutdown before ovs-tcpdump exit.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
Songtao Zhan authored and igsilya committed Apr 6, 2023
1 parent 9d84092 commit 8cba7a7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions utilities/ovs-tcpdump.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 8cba7a7

Please sign in to comment.