# HG changeset patch # User Kim Alvefur # Date 1321593204 -3600 # Node ID 0091db139229eab96de45eb0d3cc34226b7a2208 # Parent ffa4bed1b716cc077552b56177dc43310fde1724 util.pposix: Don't trust errno for success. Thanks Quince diff -r ffa4bed1b716 -r 0091db139229 util-src/pposix.c --- a/util-src/pposix.c Thu Nov 03 12:47:52 2011 +0000 +++ b/util-src/pposix.c Fri Nov 18 06:13:24 2011 +0100 @@ -395,23 +395,27 @@ return 2; } ret = initgroups(lua_tostring(L, 1), gid); - switch(errno) + if(ret) { - case 0: + 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 + { 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; }