aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/User.hsc
diff options
context:
space:
mode:
authorGravatar Ian Lynagh <igloo@earth.li>2007-11-10 23:58:05 +0000
committerGravatar Ian Lynagh <igloo@earth.li>2007-11-10 23:58:05 +0000
commit23d62156b0f9b87b4541688a535ca5aa378969a8 (patch)
treea75055939deaa7c548750b137ab2dc4db31af64a /System/Posix/User.hsc
parent4dbad9911c72b9ecbf01afb19e57460dc016d912 (diff)
Throw a proper exception if getGroupEntryForName fails to find an entry
We used to get *** Exception: getGroupEntryForName: failed (Success) Fixes trac #1655
Diffstat (limited to 'System/Posix/User.hsc')
-rw-r--r--System/Posix/User.hsc21
1 files changed, 15 insertions, 6 deletions
diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc
index d7a786d..7ec49b6 100644
--- a/System/Posix/User.hsc
+++ b/System/Posix/User.hsc
@@ -55,6 +55,10 @@ import Control.Concurrent.MVar ( newMVar, withMVar )
#ifdef HAVE_GETPWENT
import Control.Exception
#endif
+#ifdef HAVE_GETGRNAM_R
+import Control.Monad
+import System.IO.Error
+#endif
-- -----------------------------------------------------------------------------
-- user environemnt
@@ -187,13 +191,18 @@ getGroupEntryForName :: String -> IO GroupEntry
getGroupEntryForName name = do
allocaBytes (#const sizeof(struct group)) $ \pgr ->
allocaBytes grBufSize $ \pbuf ->
- alloca $ \ ppgr ->
- withCString name $ \ pstr -> do
+ alloca $ \ ppgr ->
+ withCString name $ \ pstr -> do
throwErrorIfNonZero_ "getGroupEntryForName" $
- c_getgrnam_r pstr pgr pbuf (fromIntegral grBufSize) ppgr
- throwErrnoIfNull "getGroupEntryForName" $
- peekElemOff ppgr 0
- unpackGroupEntry pgr
+ c_getgrnam_r pstr pgr pbuf (fromIntegral grBufSize) ppgr
+ r <- peekElemOff ppgr 0
+ when (r == nullPtr) $
+ ioError $ flip ioeSetErrorString "no group name"
+ $ mkIOError doesNotExistErrorType
+ "getGroupEntryForName"
+ Nothing
+ (Just name)
+ unpackGroupEntry pgr
foreign import ccall unsafe "getgrnam_r"
c_getgrnam_r :: CString -> Ptr CGroup -> CString