From: Tobias Ulmer Date: Fri, 22 Nov 2013 14:29:13 +0000 (+0100) Subject: e2: replace shell string construction and quoting with callcmd() X-Git-Tag: e2factory-2.3.15rc1~344 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=62896690971822e7c7ad84da04984fadeacce44f;p=e2factory.git e2: replace shell string construction and quoting with callcmd() Signed-off-by: Tobias Ulmer --- diff --git a/global/e2.lua b/global/e2.lua index fa6f7f7..4c0fd5c 100644 --- a/global/e2.lua +++ b/global/e2.lua @@ -50,14 +50,9 @@ local function e2(arg) local e2call = {} e2call.basename = e2lib.basename(arg[0]) - local function quoteargs(argstr) -- probably has to do escaping? - if #argstr == 0 then return "" - else return "'" .. argstr .. "'" end - end - if e2call.basename == "e2" and arg[1] and string.sub(arg[1], 1, 1) ~= "-" then e2call.toolname = "e2-" .. arg[1] - e2call.arg_string = quoteargs(table.concat(arg, "' '", 2)) + e2call.argindex = 2 elseif e2call.basename == "e2" then e2call.toolname = "e2" local opts, re = e2option.parse(arg) @@ -71,7 +66,7 @@ local function e2(arg) return 0 else e2call.toolname = e2call.basename - e2call.arg_string = quoteargs(table.concat(arg, "' '", 1)) + e2call.argindex = 1 end e2call.globaltool = buildconfig.TOOLDIR .. "/" .. e2call.toolname @@ -80,42 +75,43 @@ local function e2(arg) end local env, cmd + cmd = { buildconfig.LUA } + env = {} + if e2lib.stat(e2call.globaltool) then e2call.tool = e2call.globaltool - env = string.format("LUA_PATH='%s/?.lua' LUA_CPATH='%s/?.so'", - buildconfig.LIBDIR, buildconfig.LIBDIR) - cmd = string.format("%s %s %s %s", env, buildconfig.LUA, e2call.tool, - e2call.arg_string) - elseif not root then - return false, err.new("%s is not a global tool and we're not in a project environment", e2call.toolname) + env.LUA_PATH = string.format("%s/?.lua", buildconfig.LIBDIR) + env.LUA_CPATH= string.format("%s/?.so", buildconfig.LIBDIR) elseif root and e2lib.stat(e2call.localtool) then e2call.tool = e2call.localtool -- Search for .lc files, the local e2 may be of an older version - env = "LUA_PATH='" .. root .. "/.e2/lib/e2/?.lc;" .. - root .. "/.e2/lib/e2/?.lua' " .. - "LUA_CPATH=" .. root .. "/.e2/lib/e2/?.so" - cmd = env .. " " .. - root .. "/.e2/bin/e2-lua " .. - e2call.tool .. " " .. e2call.arg_string + env.LUA_PATH = string.format("%s/.e2/lib/e2/?.lc;%s/.e2/lib/e2/?.lua", + root, root) + env.LUA_CPATH = string.format("%s/.e2/lib/e2/?.so", root) + elseif not root then + return false, + err.new("%s is not a global tool and we're not in a ".. + "project environment", e2call.toolname) else return false, err.new("%s is neither local nor global tool", e2call.toolname) end - local function table_log(loglevel, t) - e2lib.log(loglevel, tostring(t)) - for k,v in pairs(t) do - e2lib.log(loglevel, k .. "\t->\t" .. v) + table.insert(cmd, e2call.tool) + for i,a in ipairs(arg) do + if i >= e2call.argindex then + table.insert(cmd, a) end end - table_log(3, e2call) - e2lib.log(3, "calling " .. e2call.tool) - e2lib.log(4, cmd) - local rc = os.execute(cmd) - return rc/256 + rc, re = e2lib.callcmd(cmd, {}, nil, env) + if not rc then + return false, re + end + + return rc end local rc, re = e2(arg)