#define _GNU_SOURCE
#include <lua.h>
#include <lauxlib.h>
+#include <assert.h>
#include <string.h>
#include <lxc/lxccontainer.h>
+#if LUA_VERSION_NUM < 502
+#define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
+#define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
+#endif
+
#ifdef NO_CHECK_UDATA
#define checkudata(L,i,tname) lua_touserdata(L, i)
#else
LUALIB_API int luaopen_lxc_core(lua_State *L) {
/* this is where we would initialize liblxc.so if we needed to */
- luaL_register(L, "lxc", lxc_lib_methods);
+ luaL_newlib(L, lxc_lib_methods);
lua_newuserdata(L, 0);
lua_newtable(L); /* metatable */
lua_rawset(L, -3);
luaL_newmetatable(L, CONTAINER_TYPENAME);
+ luaL_setfuncs(L, lxc_container_methods, 0);
lua_pushvalue(L, -1); /* push metatable */
lua_pushstring(L, "__gc");
lua_pushcfunction(L, container_gc);
lua_settable(L, -3);
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
- luaL_register(L, NULL, lxc_container_methods);
lua_pop(L, 1);
return 1;
}
local cgroup_path
local log_level = 3
+-- lua 5.1 compat
+if table.unpack == nil then
+ table.unpack = unpack
+end
+
-- the following two functions can be useful for debugging
function printf(...)
local function wrapper(...) io.write(string.format(...)) end
table.insert(result, val)
end
end
- return unpack(result)
+ return table.unpack(result)
end
-- read an integer from a cgroup file
return val
end
-function stats_clear(stat)
- stat.mem_used = 0
- stat.mem_limit = 0
- stat.memsw_used = 0
- stat.memsw_limit = 0
- stat.cpu_use_nanos = 0
- stat.cpu_use_user = 0
- stat.cpu_use_sys = 0
- stat.blkio = 0
-end
-
function container:stats_get(total)
local stat = {}
stat.mem_used = self:stat_get_int("memory", "memory.usage_in_bytes")
return stat
end
+local M = { container = container }
+function M.stats_clear(stat)
+ stat.mem_used = 0
+ stat.mem_limit = 0
+ stat.memsw_used = 0
+ stat.memsw_limit = 0
+ stat.cpu_use_nanos = 0
+ stat.cpu_use_user = 0
+ stat.cpu_use_sys = 0
+ stat.blkio = 0
+end
-- return configured containers found in LXC_PATH directory
-function containers_configured(names_only)
+function M.containers_configured(names_only)
local containers = {}
for dir in lfs.dir(lxc_path) do
end
-- return running containers found in cgroup fs
-function containers_running(names_only)
+function M.containers_running(names_only)
local containers = {}
local attr
lxc_path = core.default_config_path_get()
cgroup_path = cgroup_path_get()
+
+return M