lib/bb/utils: fix set_process_name
PATCH 1/1 lib/bb/utils: fix set_process_name
With Python 3 create_string_buffer needs a bytes() not a str() but as we were catching all exceptions nobody noticed.
[ YOCTO #9910 ]
--- bitbake/lib/bb/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
bitbake/lib/bb/utils.py +2 -3
@@ -1444,9 +1444,8 @@ def set_process_name(name): # This is nice to have for debugging, not essential try: libc = cdll.LoadLibrary('libc.so.6') - buff = create_string_buffer(len(name)+1) - buff.value = name - libc.prctl(15, byref(buff), 0, 0, 0) + buf = create_string_buffer(bytes(name, 'utf-8')) + libc.prctl(15, byref(buf), 0, 0, 0) except: pass
Signature · 1 line
2.8.1
Quoted 17 lines · Ross Burton
With Python 3
create_string_bufferneeds abytes()not astr()but as we were
catching all exceptions nobody noticed.[ YOCTO #9910 ]
Signed-off-by Ross Burton <[email protected]>--- bitbake/lib/bb/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)bitbake/lib/bb/utils.py +0
-0@@ -1444,9 +1444,8 @@ def set_process_name(name): # This is nice to have for debugging, not essential
bitbake/lib/bb/utils.py def set_process_name(name): · line 1451
Quoted 10 lines
bitbake/lib/bb/utils.py +2
-3try: libc = cdll.LoadLibrary('libc.so.6') - buff = create_string_buffer(len(name)+1) - buff.value = name - libc.prctl(15, byref(buff), 0, 0, 0) + buf = create_string_buffer(bytes(name, 'utf-8')) + libc.prctl(15, byref(buf), 0, 0, 0) except: pass
Why are we catching all exceptions, anyway? That's not usually a good idea.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Quoted 24 lines · Christopher Larson
Quoted 21 lines · Ross Burton
With Python 3
create_string_bufferneeds abytes()not astr()but as we were
catching all exceptions nobody noticed.[ YOCTO #9910 ]
Signed-off-by Ross Burton <[email protected]>--- bitbake/lib/bb/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)bitbake/lib/bb/utils.py +0
-2@@ -1444,9 +1444,8 @@ def set_process_name(name): # This is nice to have for debugging, not essential try: libc = cdll.LoadLibrary('libc.so.6') - buff = create_string_buffer(len(name)+1) - buff.value = name
Quoted 8 lines
bitbake/lib/bb/utils.py def set_process_name(name): · line 1451
Quoted 6 lines
bitbake/lib/bb/utils.py +2
-1- libc.prctl(15, byref(buff), 0, 0, 0) + buf = create_string_buffer(bytes(name, 'utf-8')) + libc.prctl(15, byref(buf), 0, 0, 0) except: passWhy are we catching all exceptions, anyway? That's not usually a good idea.
The variety of ways cdll and direct syscalls can fail is potentially quite large in this code block and if this doesn't work, its not really a big deal, its there for debugging so at the time it seemed reasonable just to continue if it fails. If someone wants to figure out the different cdll failure modes on various distros, I'm happy for them to do so and send a patch. Obviously it did hurt in the python3 transition but we won't do that every day...
Cheers,
Richard