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
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
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>
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.
{ "stat", get_file_statistics },
{ "symlink", create_symlink },
{ "umask", set_umask },
+ { "uname_machine", do_uname_machine },
{ "unblock", unblock_fd },
{ "unlink", do_unlink },
{ "wait", process_wait },