From 88db40393dd67e46322e4b7852c41b77fac6dcb0 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 29 Nov 2013 18:44:14 +0100 Subject: [PATCH] Replace os.execute() with e2lib.callcmd() No more shell string concatenation and quoting... Signed-off-by: Tobias Ulmer --- local/e2-help.lua | 23 ++++++++++++++--------- local/e2build.lua | 29 +++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/local/e2-help.lua b/local/e2-help.lua index 0759ab5..2cb1f2c 100644 --- a/local/e2-help.lua +++ b/local/e2-help.lua @@ -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 diff --git a/local/e2build.lua b/local/e2build.lua index d961e11..c12db3c 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -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 -- 2.39.5