diff mbox series

[ovs-dev] ovs-tcpdump: Fix incompatibilities with python3

Message ID e8cc34a176b6dd720699e6274cc61117d7766e41.1532449656.git.tredaelli@redhat.com
State Accepted
Headers show
Series [ovs-dev] ovs-tcpdump: Fix incompatibilities with python3 | expand

Commit Message

Timothy Redaelli July 24, 2018, 4:35 p.m. UTC
Opening a file with 'rw' in Python3 returns an error, moreover using 'rw' in
Python2 is wrong too since it opens the file using O_RDONLY and not by using
O_RDWR.

This commit fixes it by using the low-level os.open function with O_RDWR
as suggested by the Linux kernel (tuntap.txt) documentation.

This commit fixes also some usual bytes vs string incompatibilities.

Tested on Python 2.7.15 and Python 3.6.5

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 utilities/ovs-tcpdump.in | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Ben Pfaff July 24, 2018, 11:01 p.m. UTC | #1
On Tue, Jul 24, 2018 at 06:35:13PM +0200, Timothy Redaelli wrote:
> Opening a file with 'rw' in Python3 returns an error, moreover using 'rw' in
> Python2 is wrong too since it opens the file using O_RDONLY and not by using
> O_RDWR.
> 
> This commit fixes it by using the low-level os.open function with O_RDWR
> as suggested by the Linux kernel (tuntap.txt) documentation.
> 
> This commit fixes also some usual bytes vs string incompatibilities.
> 
> Tested on Python 2.7.15 and Python 3.6.5
> 
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>

Applied to master, thanks!
diff mbox series

Patch

diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index 91fa14e5a..17b5d48f1 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -62,8 +62,8 @@  def _install_tap_linux(tap_name, mtu_value=None):
     TUNSETIFF = 0x400454CA  # This is derived by printf() of TUNSETIFF
     TUNSETOWNER = TUNSETIFF + 2
 
-    tapdev_fd = open('/dev/net/tun', 'rw')
-    ifr = struct.pack('16sH', tap_name, IFF_TAP | IFF_NO_PI)
+    tapdev_fd = os.open('/dev/net/tun', os.O_RDWR)
+    ifr = struct.pack('16sH', tap_name.encode('utf8'), IFF_TAP | IFF_NO_PI)
     fcntl.ioctl(tapdev_fd, TUNSETIFF, ifr)
     fcntl.ioctl(tapdev_fd, TUNSETOWNER, os.getegid())
 
@@ -457,10 +457,10 @@  def main():
     pipes = _doexec(*([dump_cmd, '-i', mirror_interface] + tcpdargs))
     try:
         while pipes.poll() is None:
-            data = pipes.stdout.readline().strip('\n')
+            data = pipes.stdout.readline().strip(b'\n')
             if len(data) == 0:
                 raise KeyboardInterrupt
-            print(data)
+            print(data.decode('utf-8'))
         raise KeyboardInterrupt
     except KeyboardInterrupt:
         if pipes.poll() is None: