Software /
code /
prosody
Changeset
2438:819ba949c7bc
util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 10 Jan 2010 21:48:25 +0000 |
parents | 2437:b1ba2473fd91 |
children | 2439:511ba389147a |
files | plugins/mod_posix.lua util-src/pposix.c |
diffstat | 2 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 <stdlib.h> +#include <math.h> #include <unistd.h> #include <libgen.h> #include <sys/resource.h> @@ -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");