util-src/pposix.c
changeset 4415 0091db139229
parent 3966 e71c19dac1c7
child 4934 5a6a85719b7b
--- 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;
 }