Run runcmd() argument lists directly instead of joining them into a shell command string.
Callers that still require shell syntax continue to invoke sh -c explicitly and are left for separate cleanup. Running Popen with shell=True could return shell status 127/126. Preserve that behavior by translating the errno codes. Unrelated bug fix: Stop shifting the return code by 8 bits. subprocess.Popen.returncode is already the process exit status. Reviewed-by: Daniel Turull <[email protected]> Signed-off-by: Anders Heimer <[email protected]> --- meta/lib/oe/patch.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 2cd8de22c7..b152a2d784 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -5,6 +5,7 @@ # import os +import errno import shlex import subprocess import oe.path @@ -37,16 +38,19 @@ def runcmd(args, dir = None): # print("cwd: %s -> %s" % (olddir, dir)) try: - args = [ shlex.quote(str(arg)) for arg in args ] - cmd = " ".join(args) - # print("cmd: %s" % cmd) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + cmd = [str(arg) for arg in args] + print_cmd = shlex.join(cmd) + try: + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except OSError as exc: + status = 127 if exc.errno in (errno.ENOENT, errno.ENOTDIR) else 126 + raise CmdError(print_cmd, status, "stdout: \nstderr: %s" % exc) from exc stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') exitstatus = proc.returncode if exitstatus != 0: - raise CmdError(cmd, exitstatus >> 8, "stdout: %s\nstderr: %s" % (stdout, stderr)) + raise CmdError(print_cmd, exitstatus, "stdout: %s\nstderr: %s" % (stdout, stderr)) if " fuzz " in stdout and "Hunk " in stdout: # Drop patch fuzz info with header and footer to log file so # insane.bbclass can handle to throw error/warning
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#239394): https://lists.openembedded.org/g/openembedded-core/message/239394 Mute This Topic: https://lists.openembedded.org/mt/119940612/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
