Commit c25c2970 by Natanael Copa Committed by Stéphane Graber

lua: implement dirname in C rather than depend on external executable

Instead of popen and run external executable dirname we implement a dirname in C in the core module. We also remove the unused basename function. Signed-off-by: 's avatarNatanael Copa <ncopa@alpinelinux.org> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent ac825528
......@@ -28,6 +28,7 @@
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <lxc/lxccontainer.h>
#if LUA_VERSION_NUM < 502
......@@ -387,11 +388,18 @@ static int lxc_util_usleep(lua_State *L) {
return 0;
}
static int lxc_util_dirname(lua_State *L) {
char *path = strdupa(luaL_checkstring(L, 1));
lua_pushstring(L, dirname(path));
return 1;
}
static luaL_Reg lxc_lib_methods[] = {
{"version_get", lxc_version_get},
{"default_config_path_get", lxc_default_config_path_get},
{"container_new", container_new},
{"usleep", lxc_util_usleep},
{"dirname", lxc_util_dirname},
{NULL, NULL}
};
......
......@@ -70,22 +70,6 @@ function string:split(delim, max_cols)
return cols
end
function dirname(path)
local f,output
f = io.popen("dirname " .. path)
output = f:read('*all')
f:close()
return output:sub(1,-2)
end
function basename(path, suffix)
local f,output
f = io.popen("basename " .. path .. " " .. (suffix or ""))
output = f:read('*all')
f:close()
return output:sub(1,-2)
end
function cgroup_path_get()
local f,line,cgroup_path
......@@ -99,7 +83,7 @@ function cgroup_path_get()
end
c = line:split(" ", 6)
if (c[1] == "cgroup") then
cgroup_path = dirname(c[2])
cgroup_path = core.dirname(c[2])
break
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment