From 00f899ed9a2ff9395ab038ab688398e22d9e2fd9 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 1 Jan 2023 14:57:23 -0500 Subject: [PATCH] ENH be more precise when logging child processes --- bin/xmonad.hs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/bin/xmonad.hs b/bin/xmonad.hs index f7747db..7e7a4a4 100644 --- a/bin/xmonad.hs +++ b/bin/xmonad.hs @@ -208,6 +208,7 @@ withXmobar = bracket startXmobar stopXmobar startXmobar :: FIO (Process Handle () ()) startXmobar = do + logInfo "starting xmobar child process" p <- proc "xmobar" [] start io $ hSetBuffering (getStdin p) LineBuffering return p @@ -225,19 +226,35 @@ stopXmobar p = do logInfo "stopping xmobar child process" io $ killNoWait p -withChildDaemons :: FeatureSet -> ([Process () () ()] -> FIO a) -> FIO a +withChildDaemons + :: FeatureSet + -> ([(Utf8Builder, Process () () ())] -> FIO a) + -> FIO a withChildDaemons fs = bracket (startChildDaemons fs) stopChildDaemons -startChildDaemons :: FeatureSet -> FIO [Process () () ()] -startChildDaemons fs = catMaybes <$> mapM executeSometimes (fsDaemons fs) +startChildDaemons :: FeatureSet -> FIO [(Utf8Builder, Process () () ())] +startChildDaemons fs = catMaybes <$> mapM start (fsDaemons fs) + where + start s@(Sometimes sname _ _) = do + let sname_ = Utf8Builder $ encodeUtf8Builder sname + res <- executeSometimes s + case res of + Just p -> do + logInfo $ "starting child process: " <> sname_ + return $ Just (sname_, p) + -- don't log anything here since presumably the feature itself will log + -- an error if it fails during execution + _ -> return Nothing stopChildDaemons :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) - => [Process () () ()] + => [(Utf8Builder, Process () () ())] -> m () -stopChildDaemons ps = do - logInfo "stopping child processes" - mapM_ (liftIO . killNoWait) ps +stopChildDaemons = mapM_ stop + where + stop (n, p) = do + logInfo $ "stopping child process: " <> n + liftIO $ killNoWait p printDeps :: FIO () printDeps = withDBus_ $ \db -> do @@ -267,7 +284,7 @@ printDeps = withDBus_ $ \db -> do -- Concurrency configuration data Cleanup = Cleanup - { clChildren :: [Process () () ()] + { clChildren :: [(Utf8Builder, Process () () ())] , clXmobar :: Maybe (Process Handle () ()) , clDBusUnexporters :: [FIO ()] }