# HG changeset patch # User Matthew Wild # Date 1263160105 0 # Node ID 819ba949c7bc9d55b3479fc204b2cf0bf3035ff1 # Parent b1ba2473fd91fdf6c8ecc867d108823f27ee91c3 util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix) diff -r b1ba2473fd91 -r 819ba949c7bc plugins/mod_posix.lua --- a/plugins/mod_posix.lua Sun Jan 10 20:21:48 2010 +0000 +++ b/plugins/mod_posix.lua Sun Jan 10 21:48:25 2010 +0000 @@ -7,7 +7,7 @@ -- -local want_pposix_version = "0.3.1"; +local want_pposix_version = "0.3.2"; local pposix = assert(require "util.pposix"); if pposix._VERSION ~= want_pposix_version then module:log("warn", "Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version); end diff -r b1ba2473fd91 -r 819ba949c7bc util-src/pposix.c --- a/util-src/pposix.c Sun Jan 10 20:21:48 2010 +0000 +++ b/util-src/pposix.c Sun Jan 10 21:48:25 2010 +0000 @@ -13,9 +13,10 @@ * POSIX support functions for Lua */ -#define MODULE_VERSION "0.3.1" +#define MODULE_VERSION "0.3.2" #include +#include #include #include #include @@ -358,6 +359,18 @@ return 2; } +int lc_umask(lua_State* L) +{ + char old_mode_string[7]; + mode_t old_mode = umask(strtoul(luaL_checkstring(L, 1), NULL, 8)); + + snprintf(old_mode_string, sizeof(old_mode_string), "%03o", old_mode); + old_mode_string[sizeof(old_mode_string)-1] = 0; + lua_pushstring(L, old_mode_string); + + return 1; +} + /* Like POSIX's setrlimit()/getrlimit() API functions. * * Syntax: @@ -506,6 +519,9 @@ lua_pushcfunction(L, lc_setgid); lua_setfield(L, -2, "setgid"); + lua_pushcfunction(L, lc_umask); + lua_setfield(L, -2, "umask"); + lua_pushcfunction(L, lc_setrlimit); lua_setfield(L, -2, "setrlimit");