WIP try dup-ing the read pipe to stderr

This commit is contained in:
Nathan Dwarshuis 2023-01-02 20:57:07 -05:00
parent 774fba0c71
commit bfa7f40818
1 changed files with 6 additions and 6 deletions

View File

@ -93,26 +93,26 @@ spawnPipe
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
=> T.Text => T.Text
-> m Handle -> m Handle
spawnPipe = fmap fst . spawnPipeRW spawnPipe = liftIO . spawnPipeRW
spawnPipeRW :: MonadIO m => T.Text -> m (Handle, Handle) spawnPipeRW :: T.Text -> IO Handle
spawnPipeRW x = liftIO $ do spawnPipeRW x = do
(rI, wI) <- createPipe (rI, wI) <- createPipe
(rO, wO) <- createPipe (rO, wO) <- createPipe
-- I'm assuming the only place this matters is when xmonad is restarted (which -- I'm assuming the only place this matters is when xmonad is restarted (which
-- calls exec); since these are the ends of the pipe that xmonad will be -- calls exec); since these are the ends of the pipe that xmonad will be
-- using, this ensures they will be closed when restarting -- using, this ensures they will be closed when restarting
forM_ [wI, rO] $ \fd -> setFdOption fd CloseOnExec True forM_ [wI, rO] $ \fd -> setFdOption fd CloseOnExec True
hI <- mkHandle wI h <- mkHandle wI
hO <- mkHandle rO
void $ X.xfork $ do void $ X.xfork $ do
void $ dupTo rI stdInput void $ dupTo rI stdInput
void $ dupTo wO stdOutput void $ dupTo wO stdOutput
void $ dupTo wO stdError void $ dupTo wO stdError
executeFile "/bin/sh" False ["-c", T.unpack x] Nothing executeFile "/bin/sh" False ["-c", T.unpack x] Nothing
void $ dupTo stdError rO
closeFd rI closeFd rI
closeFd wO closeFd wO
return (hI, hO) return h
where where
mkHandle fd = do mkHandle fd = do
h <- fdToHandle fd h <- fdToHandle fd