mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-14 08:11:58 +00:00
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: Natanael Copa <ncopa@alpinelinux.org> Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
ac8255280d
commit
c25c2970a6
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user