summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2011-03-30 12:29:05 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2011-03-30 12:29:05 (GMT)
commit2550bc2eca276c999031521b80e2f4229424a53f (patch)
treefe5655c5f2676e1ec3030a912c70f54cfb28f22f
parentef7c6b153122ce86d6aa0ec655abd665d799ecec (diff)
fixed mode settingsrelease-0.1
-rw-r--r--src/lua-mq.c20
-rwxr-xr-xtest.lua2
2 files changed, 14 insertions, 8 deletions
diff --git a/src/lua-mq.c b/src/lua-mq.c
index 3f30f4e..c8c5b73 100644
--- a/src/lua-mq.c
+++ b/src/lua-mq.c
@@ -21,15 +21,16 @@ static const struct { char c; mode_t b; } M[] =
static int get_mode(mode_t *mode, const char* modestr)
{
int i;
-
- *mode = 0;
+
+ *mode = S_IRWXU;
for (i=0; i<9; i++) {
if(*modestr == 0) break;
- if (*modestr == M[i].c)
+
+ if(*modestr == M[i].c)
*mode |= M[i].b;
- else if (*modestr == '-')
+ else if(*modestr == '-')
*mode &= ~M[i].b;
- else if (*modestr == 's') {
+ else if(*modestr == 's') {
switch(i) {
case 2: *mode |= S_ISUID | S_IXUSR; break;
case 5: *mode |= S_ISGID | S_IXGRP; break;
@@ -67,11 +68,16 @@ static void push_errno(lua_State *L)
static int l_mq_create(lua_State *L)
{
mqd_t id, *ptr;
- int flags;
+ int flags, ret;
mode_t mode;
flags = get_oflags(luaL_optstring(L, 2, ""));
- mode = get_mode(luaL_optstring(L, 3, ""));
+ ret = get_mode(&mode, luaL_optstring(L, 3, ""));
+ if(ret) {
+ lua_pushnil(L);
+ lua_pushstring(L, "invalid mode specifier");
+ return 2;
+ }
id = mq_open(luaL_checkstring(L, 1), flags | O_CREAT, mode, NULL);
if(id == (mqd_t)-1) {
lua_pushnil(L);
diff --git a/test.lua b/test.lua
index 445e303..30ed5ea 100755
--- a/test.lua
+++ b/test.lua
@@ -2,7 +2,7 @@
mq = require "mq"
-q, err = mq.create("/nownext", "wo")
+q, err = mq.create("/nownext", "wo", "rw-rw----")
if q == nil then
print(err)
return 1