summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2019-09-26 20:05:15 -0400
committerJoey Hess <joeyh@joeyh.name>2019-09-26 20:05:15 -0400
commit69b3e0abcd4985bcf138eaf193dd869b9f4e0bc0 (patch)
tree9db70aaf79c882adbd245a4732a3d4741b5032a1
parent88263101ab8baf6f2b6a6a9edebc148b1bba7916 (diff)
downloaddebug-me-69b3e0abcd4985bcf138eaf193dd869b9f4e0bc0.tar.gz
Avoid a crash when run without a controlling tty, which may happen in some container environments.
-rw-r--r--CHANGELOG2
-rw-r--r--ControlWindow.hs13
2 files changed, 14 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f16e1b1..81d07f2 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,7 @@
debug-me (1.20190926) UNRELEASED; urgency=medium
+ * Avoid a crash when run without a controlling tty, which may happen
+ in some container environments.
* Update to lts-13.29, support ghc 8.6.5, and aeson 1.4.
-- Joey Hess <id@joeyh.name> Thu, 26 Sep 2019 19:44:58 -0400
diff --git a/ControlWindow.hs b/ControlWindow.hs
index bd79d0f..29c81c9 100644
--- a/ControlWindow.hs
+++ b/ControlWindow.hs
@@ -98,9 +98,20 @@ type Response = String
type PromptChan = TChan Prompt
type ResponseChan = TChan Response
+-- | Get a name for the debug-me user. When possible this will be the
+-- actual username, but failing that, anything reasonable will do,
+-- since it's only ever displayed to the person they are communicating
+-- with.
+getUserName :: IO String
+getUserName = do
+ loginname <- try getLoginName :: IO (Either SomeException String)
+ case loginname of
+ Right n -> return n
+ Left _ -> return "user"
+
collectOutput :: TMChan ControlOutput -> PromptChan -> ResponseChan -> IO ()
collectOutput ochan promptchan responsechan = do
- myusername <- fromString <$> getLoginName
+ myusername <- fromString <$> getUserName
loop myusername
where
loop myusername = do