]> git.e2factory.org Git - e2factory.git/commitdiff
Replace e2lib.get_sys_arch() with uname_machine()
authorTobias Ulmer <tu@emlix.com>
Thu, 29 Aug 2013 17:16:58 +0000 (19:16 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:01:23 +0000 (15:01 +0100)
No more parsing of uname output...

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
generic/le2lib.c

index 66280e90dcb4d51e91bb3dd8a37184efd7490fc0..4acf19670bcb597469eac41bdf1cb34ca79ec03f 100644 (file)
@@ -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
index c6f2242af8859f2b66d615b8409755b5fbd92323..e12a0a0482d1ee727c7d32bc0dd9e03fb269f918 100644 (file)
@@ -25,6 +25,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
 
+#include <sys/utsname.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -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 },