On Thu, 5 Sep 2013 09:41:12 -0400 Dwight Engen <dwight.en...@oracle.com> wrote:
> fix a bug in the parsing of /proc/mounts (from Natanael Copa > <nc...@alpinelinux.org>) > > remove lxc subdir in cgroup paths > > remove extraneous debug printfs > > remove extra call to stats_clear > > Tested lxc-top, and apitest.lua on both lua 5.1 and 5.2 > > Signed-off-by: Dwight Engen <dwight.en...@oracle.com> > --- > configure.ac | 10 +++++++++- > src/lua-lxc/Makefile.am | 4 ++-- > src/lua-lxc/lxc.lua | 50 > ++++++++++++++++++++++--------------------------- > src/lxc/lxc-top | 14 ++++++++++---- > 4 files changed, 43 insertions(+), 35 deletions(-) > > diff --git a/configure.ac b/configure.ac > index df9a44b..f6f067d 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -164,9 +164,17 @@ AC_ARG_ENABLE([lua], > AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"]) > > AM_COND_IF([ENABLE_LUA], > - [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You > must install lua-devel for lua 5.1])]) > + [AC_CHECK_PROG([LUA],[lua],[lua],[no]) > + PKG_CHECK_MODULES([LUADEVEL], [$LUAPKGCONFIG >= > 5.1],[],[AC_MSG_ERROR([You must install lua-devel])]) > AC_DEFINE_UNQUOTED([ENABLE_LUA], 1, [Lua is available])]) > > +AS_IF([test "x$LUA" != "xno"], > + [AC_MSG_CHECKING([for lua version]) > + LUA_VERSION=`$LUA -e 'print(_VERSION)' | awk '{print $2}'` > + AC_MSG_RESULT([$LUA_VERSION]) > + AC_SUBST([LUA_VERSION])]) > + > + > # Optional test binaries > AC_ARG_ENABLE([tests], > [AC_HELP_STRING([--enable-tests], [build test/example binaries])], What if you have both lua 5.1 and 5.2 installed (eg debian/ubuntu) and want build against lua 5.1? On Ubuntu I get: lua -e 'print(_VERSION)' | awk '{print $2}' 5.2 but i might want use the lua5.1.pc And what happens if you cross-compile? (cross-compiling is a new can of worms that i don't think we should worry too much about) This is why i dropped the idea of running lua binary and try to rely on pkg-config info only. Even if fedora does not provide INSTALL_[CL]MOD it provides V: [ncopa@localhost ~]$ uname -a Linux localhost.localdomain 3.9.5-301.fc19.x86_64 #1 SMP Tue Jun 11 19:39:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [ncopa@localhost ~]$ pkg-config --variable V lua 5.1 We can fallback to this in case INSTALL_[CL]MOD is missing. INSTALL_[CL]MOD appears to be available on Ubuntu(/Debian?), Arch Linux and Alpine Linux. Suse I don't know. > diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top > index 31aaecf..969f1f7 100755 > --- a/src/lxc/lxc-top > +++ b/src/lxc/lxc-top > @@ -97,9 +97,16 @@ end > > function usleep(n) > if (n ~= 0) then > - ret = os.execute("usleep " .. tonumber(n)) > - if (ret ~= 0) then > - os.exit(0) > + local ret = os.execute("usleep " .. tonumber(n)) > + if (string.sub(_VERSION, 5) == "5.2") then > + if (ret == nil) then > + os.exit(0) > + end > + end > + if (string.sub(_VERSION, 5) == "5.1") then > + if (ret ~= 0) then > + os.exit(0) > + end > end > end > end How about implement a tiny usleep in core in C instead: diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c index d404707..504e147 100644 --- a/src/lua-lxc/core.c +++ b/src/lua-lxc/core.c @@ -27,11 +27,13 @@ #include <lauxlib.h> #include <assert.h> #include <string.h> +#include <unistd.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)) +#define luaL_checkunsigned(L,n) luaL_checknumber(L,n) #endif #ifdef NO_CHECK_UDATA @@ -379,10 +381,17 @@ static int lxc_default_config_path_get(lua_State *L) { return 1; } +/* utility functions */ +static int lxc_util_usleep(lua_State *L) { + usleep((useconds_t)luaL_checkunsigned(L, 1)); + return 0; +} + 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}, {NULL, NULL} }; diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top index 31aaecf..8e8bafb 100755 --- a/src/lxc/lxc-top +++ b/src/lxc/lxc-top @@ -22,6 +22,7 @@ -- local lxc = require("lxc") +local core = require("lxc.core") local getopt = require("alt_getopt") local lfs = require("lfs") @@ -95,15 +96,6 @@ function strsisize(size, width) return string.format("%3d.00 ", size) end -function usleep(n) - if (n ~= 0) then - ret = os.execute("usleep " .. tonumber(n)) - if (ret ~= 0) then - os.exit(0) - end - end -end - function tty_lines() local rows = 25 local f = assert(io.popen("stty -a | head -n 1")) @@ -238,5 +230,5 @@ do end stats_print(string.format("TOTAL (%-2d)", #containers), stats_total) io.flush() - usleep(optarg["d"] * 1000000) + core.usleep(optarg["d"] * 1000000) end ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel