Changeset

4415:0091db139229

util.pposix: Don't trust errno for success. Thanks Quince
author Kim Alvefur <zash@zash.se>
date Fri, 18 Nov 2011 06:13:24 +0100
parents 4413:ffa4bed1b716
children 4416:03e1295d599a
files util-src/pposix.c
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }