From: Tobias Ulmer Date: Thu, 29 Aug 2013 17:16:58 +0000 (+0200) Subject: Replace e2lib.get_sys_arch() with uname_machine() X-Git-Tag: e2factory-2.3.15rc1~461 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=42b87fe8a0769c779d365bebca84a3f1494f5a37;p=e2factory.git Replace e2lib.get_sys_arch() with uname_machine() No more parsing of uname output... Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 66280e9..4acf196 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -459,7 +459,7 @@ function e2lib.init2() end -- get host system architecture - host_system_arch, re = e2lib.get_sys_arch() + host_system_arch, re = e2lib.uname_machine() if not host_system_arch then return false, e:cat(re) end @@ -2123,36 +2123,18 @@ function e2lib.tar(argv) return e2lib.call_tool_argv("tar", argv) end ---- Get system architecture. +--- Get machine system architecture. -- @return Machine hardware name as a string, false on error. -- @return Error object on failure. -function e2lib.get_sys_arch() - local rc, re, e, uname, cmd, p, msg, l, arch +function e2lib.uname_machine() + local machine, errstring = le2lib.uname_machine() - e = err.new("getting host system architecture failed") - - uname, re = tools.get_tool("uname") - if not uname then - return false, e:cat(re) - end - - cmd = string.format("%s -m", e2lib.shquote(uname)) - p, msg = io.popen(cmd, "r") - if not p then - return false, e:cat(msg) - end - - l, msg = p:read() - if not l then - return false, e:cat(msg) - end - - arch = l:match("(%S+)") - if not arch then - return false, e:append("%s: %s: cannot parse", cmd, l) + if not machine then + return false, err.new("getting host system architecture failed: %s", + errstring) end - return arch + return machine end --- return a table of parent directories diff --git a/generic/le2lib.c b/generic/le2lib.c index c6f2242..e12a0a0 100644 --- a/generic/le2lib.c +++ b/generic/le2lib.c @@ -25,6 +25,8 @@ along with this program. If not, see . */ +#include + #include #include #include @@ -541,6 +543,23 @@ do_kill(lua_State *lua) return 1; } +static int +do_uname_machine(lua_State *lua) +{ + struct utsname uts; + + if (uname(&uts) != 0) { + lua_pushboolean(lua, 0); + lua_pushstring(lua, strerror(errno)); + + return 2; + } + + lua_pushstring(lua, uts.machine); + + return 1; +} + /* * Hook that gets called once an interrupt has been requested. @@ -598,6 +617,7 @@ static luaL_Reg lib[] = { { "stat", get_file_statistics }, { "symlink", create_symlink }, { "umask", set_umask }, + { "uname_machine", do_uname_machine }, { "unblock", unblock_fd }, { "unlink", do_unlink }, { "wait", process_wait },