Skip to contentSkip to conversation

meta: Cleanup getstatusoutput usage

PATCH In review Robert Yang 2 participants 7 messages Aug 23, 2018

lore
Share & tools
lore
#0 lore raw

cover meta: Cleanup getstatusoutput usage

The following changes since commit 1314a6953aa647706107557faaba8574e307d2bd:

patch: fix CVE-2018-6952 (2018-08-23 07:45:32 +0100)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib rbt/subprocess
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=rbt/subprocess

Robert Yang (5):
lib/oe/gpg_sign.py: Clean up getstatusoutput usage lib/oe/patch.py: Clean up getstatusoutput usage kernel-yocto.bbclass: Clean up getstatusoutput usage
psplash: Clean up getstatusoutput usage compress_doc.bbclass: Clean up getstatusoutput usage

 meta/classes/compress_doc.bbclass        |  7 ++++---
 meta/classes/kernel-yocto.bbclass        |  5 +++--
 meta/lib/oe/gpg_sign.py                  | 15 +++++----------
 meta/lib/oe/patch.py                     |  3 ++-
 meta/recipes-core/psplash/psplash_git.bb |  5 +++--
 5 files changed, 17 insertions(+), 18 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 lib/oe/gpg_sign.py: Clean up getstatusoutput usage

Replace usage of oe.utils.getstatusoutput() with direct subprocess calls.

---
 meta/lib/oe/gpg_sign.py | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
meta/lib/oe/gpg_sign.py +5 -10
index b172729..ccd5aee 100644
@@ -3,6 +3,8 @@ import os
 
 import bb
 import oe.utils
+import subprocess
+import shlex
 
 class LocalSigner(object):
     """Class for handling local (on the build host) signing"""
@@ -23,10 +25,7 @@ class LocalSigner(object):
         if armor:
             cmd += "--armor "
         cmd += keyid
-        status, output = oe.utils.getstatusoutput(cmd)
-        if status:
-            raise bb.build.FuncFailed('Failed to export gpg public key (%s): %s' %
-                                      (keyid, output))
+        subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT)
 
     def sign_rpms(self, files, keyid, passphrase, digest, sign_chunk, fsk=None, fsk_password=None):
         """Sign RPM files"""
@@ -48,13 +47,10 @@ class LocalSigner(object):
 
         # Sign in chunks
         for i in range(0, len(files), sign_chunk):
-            status, output = oe.utils.getstatusoutput(cmd + ' '.join(files[i:i+sign_chunk]))
-            if status:
-                raise bb.build.FuncFailed("Failed to sign RPM packages: %s" % output)
+            subprocess.check_output(shlex.split(cmd + ' '.join(files[i:i+sign_chunk])), stderr=subprocess.STDOUT)
 
     def detach_sign(self, input_file, keyid, passphrase_file, passphrase=None, armor=True):
         """Create a detached signature of a file"""
-        import subprocess
 
         if passphrase_file and passphrase:
             raise Exception("You should use either passphrase_file of passphrase, not both")
@@ -100,7 +96,6 @@ class LocalSigner(object):
 
     def get_gpg_version(self):
         """Return the gpg version as a tuple of ints"""
-        import subprocess
         try:
             ver_str = subprocess.check_output((self.gpg_bin, "--version", "--no-permission-warning")).split()[2].decode("utf-8")
             return tuple([int(i) for i in ver_str.split("-")[0].split('.')])
@@ -114,7 +109,7 @@ class LocalSigner(object):
         if self.gpg_path:
             cmd += "--homedir %s " % self.gpg_path
         cmd += sig_file
-        status, _ = oe.utils.getstatusoutput(cmd)
+        status = subprocess.call(shlex.split(cmd))
         ret = False if status else True
         return ret
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 lib/oe/patch.py: Clean up getstatusoutput usage

In reply to Robert Yang

We can't use subprocess.check_output() or subprocess.call() here since the one who invokes runcmd() needs handle CmdError() exception (error out or ignore it).

---
 meta/lib/oe/patch.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/lib/oe/patch.py +2 -1
index af7aa52..e0f0604 100644
@@ -21,6 +21,7 @@ class CmdError(bb.BBHandledException):
 
 def runcmd(args, dir = None):
     import pipes
+    import subprocess
 
     if dir:
         olddir = os.path.abspath(os.curdir)
@@ -33,7 +34,7 @@ def runcmd(args, dir = None):
         args = [ pipes.quote(str(arg)) for arg in args ]
         cmd = " ".join(args)
         # print("cmd: %s" % cmd)
-        (exitstatus, output) = oe.utils.getstatusoutput(cmd)
+        (exitstatus, output) = subprocess.getstatusoutput(cmd)
         if exitstatus != 0:
             raise CmdError(cmd, exitstatus >> 8, output)
         if " fuzz " in output:
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 kernel-yocto.bbclass: Clean up getstatusoutput usage

In reply to Robert Yang

Replace usage of oe.utils.getstatusoutput() with direct subprocess calls.

---
 meta/classes/kernel-yocto.bbclass | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/classes/kernel-yocto.bbclass +3 -2
index 077a1ab..8c5667d 100644
@@ -322,6 +322,7 @@ addtask kernel_configme before do_configure after do_patch
 
 python do_kernel_configcheck() {
     import re, string, sys
+    import subprocess
 
     # if KMETA isn't set globally by a recipe using this routine, we need to
     # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
@@ -333,10 +334,10 @@ python do_kernel_configcheck() {
     pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH'), "${S}/scripts/util/")
 
     cmd = d.expand("scc --configs -o ${S}/.kernel-meta")
-    ret, configs = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
+    configs = subprocess.getoutput("%s%s" % (pathprefix, cmd))
 
     cmd = d.expand("cd ${S}; kconf_check --report -o ${S}/%s/cfg/ ${B}/.config ${S} %s" % (kmeta,configs))
-    ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
+    result = subprocess.getoutput("%s%s" % (pathprefix, cmd))
 
     config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
     bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 3/5] kernel-yocto.bbclass: Clean up getstatusoutput usage

ignore this patch. I already have a more complete version that was sent previously and is in my queue I'll send later today.

Bruce

Quoted 40 lines · Robert Yang

Replace usage of oe.utils.getstatusoutput() with direct subprocess calls.

---
 meta/classes/kernel-yocto.bbclass | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/classes/kernel-yocto.bbclass +3 -3
index 077a1ab..8c5667d 100644
@@ -322,6 +322,7 @@ addtask kernel_configme before do_configure after do_patch
 
 python do_kernel_configcheck() {
     import re, string, sys
+    import subprocess
 
     # if KMETA isn't set globally by a recipe using this routine, we need to
     # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
@@ -333,10 +334,10 @@ python do_kernel_configcheck() {
     pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH'), "${S}/scripts/util/")
 
     cmd = d.expand("scc --configs -o ${S}/.kernel-meta")
-    ret, configs = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
+    configs = subprocess.getoutput("%s%s" % (pathprefix, cmd))
 
     cmd = d.expand("cd ${S}; kconf_check --report -o ${S}/%s/cfg/ ${B}/.config ${S} %s" % (kmeta,configs))
-    ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
+    result = subprocess.getoutput("%s%s" % (pathprefix, cmd))
 
     config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
     bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
--

2.7.4

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end"
#5 lore raw

PATCH 4/5 psplash: Clean up getstatusoutput usage

In reply to Robert Yang

Replace usage of oe.utils.getstatusoutput() with direct subprocess calls.

---
 meta/recipes-core/psplash/psplash_git.bb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/recipes-core/psplash/psplash_git.bb +3 -2
index aab2c03..3ad1ef4 100644
@@ -73,6 +73,8 @@ ALTERNATIVE_LINK_NAME[psplash] = "${bindir}/psplash"
 
 python do_compile () {
     import shutil
+    import subprocess
+    import shlex
 
     # Build a separate executable for each splash image
     workdir = d.getVar('WORKDIR')
@@ -82,8 +84,7 @@ python do_compile () {
     outputfiles = d.getVar('SPLASH_INSTALL').split()
     for localfile, outputfile in zip(localfiles, outputfiles):
         if localfile.endswith(".png"):
-            outp = oe.utils.getstatusoutput('%s %s POKY' % (convertscript, os.path.join(workdir, localfile)))
-            print(outp[1])
+            subprocess.call(shlex.split('%s %s POKY' % (convertscript, os.path.join(workdir, localfile))))
             fbase = os.path.splitext(localfile)[0]
             shutil.copyfile("%s-img.h" % fbase, destfile)
         else:
Signature · 1 line
2.7.4
#6 lore raw

PATCH 5/5 compress_doc.bbclass: Clean up getstatusoutput usage

In reply to Robert Yang

Replace usage of oe.utils.getstatusoutput() with direct subprocess calls.

---
 meta/classes/compress_doc.bbclass | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
meta/classes/compress_doc.bbclass +4 -3
index 069d534..45bb8ff 100644
@@ -79,6 +79,7 @@ def _collect_hardlink(hardlink_dict, file):
     return hardlink_dict
 
 def _process_hardlink(hardlink_dict, compress_mode, shell_cmds, decompress=False):
+    import subprocess
     for target in hardlink_dict:
         if decompress:
             compress_format = _get_compress_format(target, shell_cmds.keys())
@@ -87,7 +88,7 @@ def _process_hardlink(hardlink_dict, compress_mode, shell_cmds, decompress=False
         else:
             cmd = "%s -f %s" % (shell_cmds[compress_mode], target)
             bb.note('compress hardlink %s' % target)
-        (retval, output) = oe.utils.getstatusoutput(cmd)
+        (retval, output) = subprocess.getstatusoutput(cmd)
         if retval:
             bb.warn("de/compress file failed %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
             return
@@ -176,7 +177,7 @@ def compress_doc(topdir, compress_mode, compress_cmds):
                 # Normal file
                 elif os.path.isfile(file):
                     cmd = "%s %s" % (compress_cmds[compress_mode], file)
-                    (retval, output) = oe.utils.getstatusoutput(cmd)
+                    (retval, output) = subprocess.getstatusoutput(cmd)
                     if retval:
                         bb.warn("compress failed %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
                         continue
@@ -206,7 +207,7 @@ def decompress_doc(topdir, compress_mode, decompress_cmds):
                 # Normal file
                 elif os.path.isfile(file):
                     cmd = "%s %s" % (decompress_cmds[compress_format], file)
-                    (retval, output) = oe.utils.getstatusoutput(cmd)
+                    (retval, output) = subprocess.getstatusoutput(cmd)
                     if retval:
                         bb.warn("decompress failed %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
                         continue
Signature · 1 line
2.7.4