Fix BPF(src_file="foo")
authorJerome Marchand <jmarchan@redhat.com>
Tue, 27 Apr 2021 13:13:12 +0000 (15:13 +0200)
committeryonghong-song <ys114321@gmail.com>
Thu, 29 Apr 2021 16:03:36 +0000 (09:03 -0700)
Since commit 75f20a15 ("Use string type for comparison to PATH
elements"), src_file isn't working anymore. Somehow, two wrongs
(ArgString __str__() returning a bytes object and joining a bytes and
what was supposed to be a string) did make a right.

It fixes the following error in netqtop and deadlock:
Traceback (most recent call last):
  File "/usr/share/bcc/tools/netqtop", line 207, in <module>
    b = BPF(src_file = EBPF_FILE)
  File "/usr/lib/python3.6/site-packages/bcc/__init__.py", line 335, in __init__
    src_file = BPF._find_file(src_file)
  File "/usr/lib/python3.6/site-packages/bcc/__init__.py", line 255, in _find_file
    t = b"/".join([os.path.abspath(os.path.dirname(argv0.__str__())), filename])
TypeError: sequence item 0: expected a bytes-like object, str found

src/python/bcc/__init__.py

index 90562cd77adacc77166437d256d044621ee1324c..eabe0a55f9583173b0ee03566c20a3a14d0da0c3 100644 (file)
@@ -252,7 +252,7 @@ class BPF(object):
         if filename:
             if not os.path.isfile(filename):
                 argv0 = ArgString(sys.argv[0])
-                t = b"/".join([os.path.abspath(os.path.dirname(argv0.__str__())), filename])
+                t = b"/".join([os.path.abspath(os.path.dirname(argv0.__bytes__())), filename])
                 if os.path.isfile(t):
                     filename = t
                 else: