]> git.e2factory.org Git - e2factory.git/commitdiff
Replace os.execute() with e2lib.callcmd()
authorTobias Ulmer <tu@emlix.com>
Fri, 29 Nov 2013 17:44:14 +0000 (18:44 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
No more shell string concatenation and quoting...

Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/e2-help.lua
local/e2build.lua

index 0759ab54d57e819d744098787facb43ef9906642..2cb1f2c32e3468b4f8fad67be8ffebfaeedc5990 100644 (file)
@@ -173,22 +173,27 @@ local function display_man_page(doc)
     local rc, re, e
     local cmd = {}
 
-    local viewer = tools.get_tool("man")
+    local viewer, re = tools.get_tool("man")
     if not viewer then
         return false, err.new("no man page viewer is available")
     end
-    table.insert(cmd, e2lib.shquote(viewer))
+    table.insert(cmd, viewer)
 
-    local viewerflags = tools.get_tool_flags("man")
-    if viewerflags and #viewerflags > 0 then
-        table.insert(cmd, table.concat(viewerflags, " "))
+    local viewerflags, re = tools.get_tool_flags("man")
+    if not viewerflags then
+        return false, re
+    end
+
+    for _,flag in ipairs(viewerflags) do
+        table.insert(cmd, flag)
     end
 
-    table.insert(cmd, e2lib.shquote(e2lib.join(doc.path, doc.filename)))
+    table.insert(cmd, e2lib.join(doc.path, doc.filename))
 
-    rc = os.execute(table.concat(cmd, ' '))
-    rc = rc/256 -- XXX: os.execute
-    if rc ~= 0 then
+    rc, re = e2lib.callcmd(cmd, {})
+    if not rc then
+        return false, re
+    elseif rc ~= 0 then
         return false,
             err.new("man page viewer terminated with exit code %d", rc)
     end
index d961e11bb7b6922fa376d5454c81beb460f20056..c12db3c43cc54768497b88af3888fe7e802996c2 100644 (file)
@@ -355,10 +355,6 @@ end
 function e2build.enter_playground(info, r, chroot_command)
     local rc, re, e, res, e2_su, cmd
 
-    if not chroot_command then
-        chroot_command = "/bin/bash"
-    end
-
     res = info.results[r]
     e = err.new("entering playground")
 
@@ -367,12 +363,29 @@ function e2build.enter_playground(info, r, chroot_command)
         return false, e:cat(re)
     end
 
-    cmd = string.format("%s %s chroot_2_3 '%s' %s",
-        res.build_config.chroot_call_prefix, e2_su,
-        res.build_config.base, chroot_command)
+    cmd = {
+        res.build_config.chroot_call_prefix,
+        e2_su,
+        "chroot_2_3",
+        res.build_config.base,
+    }
+
+    if chroot_command then
+        table.insert(cmd, "/bin/sh")
+        table.insert(cmd, "-c")
+        table.insert(cmd, chroot_command)
+    else
+        table.insert(cmd, "/bin/bash")
+    end
+
     e2tool.set_umask(info)
+    rc, re = e2lib.callcmd(cmd, {})
+    if not rc then
+        e2tool.reset_umask(info)
+        return false, e:cat(re)
+    end
     -- return code depends on user commands. Ignore.
-    os.execute(cmd)
+
     e2tool.reset_umask(info)
 
     return true