summaryrefslogtreecommitdiff
path: root/Utility/UserInfo.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility/UserInfo.hs')
-rw-r--r--Utility/UserInfo.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/Utility/UserInfo.hs b/Utility/UserInfo.hs
index d504fa5..17ce8db 100644
--- a/Utility/UserInfo.hs
+++ b/Utility/UserInfo.hs
@@ -14,7 +14,7 @@ module Utility.UserInfo (
myUserGecos,
) where
-import Utility.Env
+import Utility.Env.Basic
import Utility.Exception
#ifndef mingw32_HOST_OS
import Utility.Data
@@ -47,8 +47,8 @@ myUserName = myVal env userName
#endif
myUserGecos :: IO (Maybe String)
--- userGecos crashes on Android and is not available on Windows.
-#if defined(__ANDROID__) || defined(mingw32_HOST_OS)
+-- userGecos is not available on Windows.
+#if defined(mingw32_HOST_OS)
myUserGecos = return Nothing
#else
myUserGecos = eitherToMaybe <$> myVal [] userGecos
@@ -57,10 +57,13 @@ myUserGecos = eitherToMaybe <$> myVal [] userGecos
myVal :: [String] -> (UserEntry -> String) -> IO (Either String String)
myVal envvars extract = go envvars
where
+ go [] = either (const $ envnotset) (Right . extract) <$> get
+ go (v:vs) = maybe (go vs) (return . Right) =<< getEnv v
#ifndef mingw32_HOST_OS
- go [] = Right . extract <$> (getUserEntryForID =<< getEffectiveUserID)
+ -- This may throw an exception if the system doesn't have a
+ -- passwd file etc; don't let it crash.
+ get = tryNonAsync $ getUserEntryForID =<< getEffectiveUserID
#else
- go [] = return $ either Left (Right . extract) $
- Left ("environment not set: " ++ show envvars)
+ get = return envnotset
#endif
- go (v:vs) = maybe (go vs) (return . Right) =<< getEnv v
+ envnotset = Left ("environment not set: " ++ show envvars)