From: Anders Heimer Date: Wed, 24 Jun 2026 12:43:59 +0000 (+0200) Subject: oe/patch: drop shell=True from runcmd X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef8eafe6059178bf375188b5edee1d26aa0a91ac;p=thirdparty%2Fopenembedded%2Fopenembedded-core.git oe/patch: drop shell=True from runcmd 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 Signed-off-by: Anders Heimer Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- 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