mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-14 12:47:41 +00:00
lua: implement usleep in C module
So we avoid running os.execute Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
12e93188de
commit
ac8255280d
@ -27,11 +27,13 @@
|
|||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <lxc/lxccontainer.h>
|
#include <lxc/lxccontainer.h>
|
||||||
|
|
||||||
#if LUA_VERSION_NUM < 502
|
#if LUA_VERSION_NUM < 502
|
||||||
#define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
|
#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_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
|
||||||
|
#define luaL_checkunsigned(L,n) luaL_checknumber(L,n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NO_CHECK_UDATA
|
#ifdef NO_CHECK_UDATA
|
||||||
@ -379,10 +381,17 @@ static int lxc_default_config_path_get(lua_State *L) {
|
|||||||
return 1;
|
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[] = {
|
static luaL_Reg lxc_lib_methods[] = {
|
||||||
{"version_get", lxc_version_get},
|
{"version_get", lxc_version_get},
|
||||||
{"default_config_path_get", lxc_default_config_path_get},
|
{"default_config_path_get", lxc_default_config_path_get},
|
||||||
{"container_new", container_new},
|
{"container_new", container_new},
|
||||||
|
{"usleep", lxc_util_usleep},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local lxc = require("lxc")
|
local lxc = require("lxc")
|
||||||
|
local core = require("lxc.core")
|
||||||
local getopt = require("alt_getopt")
|
local getopt = require("alt_getopt")
|
||||||
local lfs = require("lfs")
|
local lfs = require("lfs")
|
||||||
|
|
||||||
@ -95,15 +96,6 @@ function strsisize(size, width)
|
|||||||
return string.format("%3d.00 ", size)
|
return string.format("%3d.00 ", size)
|
||||||
end
|
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()
|
function tty_lines()
|
||||||
local rows = 25
|
local rows = 25
|
||||||
local f = assert(io.popen("stty -a | head -n 1"))
|
local f = assert(io.popen("stty -a | head -n 1"))
|
||||||
@ -238,5 +230,5 @@ do
|
|||||||
end
|
end
|
||||||
stats_print(string.format("TOTAL (%-2d)", #containers), stats_total)
|
stats_print(string.format("TOTAL (%-2d)", #containers), stats_total)
|
||||||
io.flush()
|
io.flush()
|
||||||
usleep(optarg["d"] * 1000000)
|
core.usleep(optarg["d"] * 1000000)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user