catch exceptions from getEffectiveUserID
This fixes a crash when using the linux_standalone build in termux on android. This commit was sponsored by Jeff Goeke-Smith on Patreon.
This commit is contained in:
parent
ec7262bb87
commit
526243d6f5
1 changed files with 9 additions and 6 deletions
|
@ -57,10 +57,13 @@ myUserGecos = eitherToMaybe <$> myVal [] userGecos
|
|||
myVal :: [String] -> (UserEntry -> String) -> IO (Either String String)
|
||||
myVal envvars extract = go envvars
|
||||
where
|
||||
#ifndef mingw32_HOST_OS
|
||||
go [] = Right . extract <$> (getUserEntryForID =<< getEffectiveUserID)
|
||||
#else
|
||||
go [] = return $ either Left (Right . extract) $
|
||||
Left ("environment not set: " ++ show envvars)
|
||||
#endif
|
||||
go [] = either (const $ envnotset) (Right . extract) <$> get
|
||||
go (v:vs) = maybe (go vs) (return . Right) =<< getEnv v
|
||||
#ifndef mingw32_HOST_OS
|
||||
-- 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
|
||||
get = return envnotset
|
||||
#endif
|
||||
envnotset = Left ("environment not set: " ++ show envvars)
|
||||
|
|
Loading…
Reference in a new issue