From 51e01dfd14f37ff88f15e8990dce089b3944fc3c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 18 Nov 2011 06:13:24 +0100 Subject: util.pposix: Don't trust errno for success. Thanks Quince --- util-src/pposix.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'util-src') diff --git a/util-src/pposix.c b/util-src/pposix.c index ffd21288..dae48390 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -395,23 +395,27 @@ int lc_initgroups(lua_State* L) return 2; } ret = initgroups(lua_tostring(L, 1), gid); - switch(errno) + if(ret) + { + switch(errno) + { + case ENOMEM: + lua_pushnil(L); + lua_pushstring(L, "no-memory"); + break; + case EPERM: + lua_pushnil(L); + lua_pushstring(L, "permission-denied"); + break; + default: + lua_pushnil(L); + lua_pushstring(L, "unknown-error"); + } + } + else { - case 0: lua_pushboolean(L, 1); lua_pushnil(L); - break; - case ENOMEM: - lua_pushnil(L); - lua_pushstring(L, "no-memory"); - break; - case EPERM: - lua_pushnil(L); - lua_pushstring(L, "permission-denied"); - break; - default: - lua_pushnil(L); - lua_pushstring(L, "unknown-error"); } return 2; } -- cgit v1.2.3