X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util-src%2Fpposix.c;h=4ff84bde2440f4aed4aac6b5f12dfbaddf712864;hb=edd92fbc05125aab0b1fa14599f74bb5419f96a2;hp=1b1f85fd75d7c272bd303a4b12d134c7b430f03d;hpb=548870f42e8b84845bcd12389cb931026479c5a8;p=prosody.git diff --git a/util-src/pposix.c b/util-src/pposix.c index 1b1f85fd..4ff84bde 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -13,7 +13,7 @@ * POSIX support functions for Lua */ -#define MODULE_VERSION "0.3.4" +#define MODULE_VERSION "0.3.5" #include #include @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -553,6 +554,29 @@ int lc_abort(lua_State* L) return 0; } +int lc_uname(lua_State* L) +{ + struct utsname uname_info; + if(uname(&uname_info) != 0) + { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } + lua_newtable(L); + lua_pushstring(L, uname_info.sysname); + lua_setfield(L, -2, "sysname"); + lua_pushstring(L, uname_info.nodename); + lua_setfield(L, -2, "nodename"); + lua_pushstring(L, uname_info.release); + lua_setfield(L, -2, "release"); + lua_pushstring(L, uname_info.version); + lua_setfield(L, -2, "version"); + lua_pushstring(L, uname_info.machine); + lua_setfield(L, -2, "machine"); + return 1; +} + /* Register functions */ int luaopen_util_pposix(lua_State *L) @@ -582,6 +606,8 @@ int luaopen_util_pposix(lua_State *L) { "setrlimit", lc_setrlimit }, { "getrlimit", lc_getrlimit }, + { "uname", lc_uname }, + { NULL, NULL } };