From cbf92262721879286a85d35dc528ae941f706450 Mon Sep 17 00:00:00 2001 From: Ulrik de Muelenaere Date: Fri, 29 Mar 2024 22:03:21 -0400 Subject: Fix waitForProcess errors when configuration is recompiled Previously, xmobar would ignore SIGCHLD, but only when the configuration is recompiled. This means child processes would not leave zombies, so that waiting for them to exit (either directly by calling waitForProcess, or indirectly through another function from System.Process, like system or readProcessWithExitCode) would produce an error. This breaks the Alsa, Com (#657) and NotmuchMail plugins, as well as the tag (#687) and low battery action (#688). As far as I can tell, bracketing the recompilation in uninstallSignalHandlers and installSignalHandlers was inherited from xmonad. In xmonad, SIGPIPE and SIGCHLD are always ignored (installSignalHandlers is called at the start of xmonad and launch), so the bracket is necessary to be able to wait for the compiler or build script to exit. Since xmobar does not otherwise ignore the signals, it is not necessary to change signal handlers at all during recompilation. Removing it leaves the default action for SIGCHLD, which fixes the issues described above. Fixes #657, #687 and #688. --- changelog.md | 2 ++ src/Xmobar/App/Compile.hs | 27 ++------------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/changelog.md b/changelog.md index 6410188..e7893e9 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,8 @@ - The `Kbd` monitor is not clickable (thanks, Enrico Maria) - Fix zombie processes left by `` tag and low battery action +- Fix plugins such as `Alsa` and `Com` not working when configuration is + recompiled (#657) ## Version 0.47.4 (March, 2024) diff --git a/src/Xmobar/App/Compile.hs b/src/Xmobar/App/Compile.hs index 368c3e6..5d1f48d 100644 --- a/src/Xmobar/App/Compile.hs +++ b/src/Xmobar/App/Compile.hs @@ -20,20 +20,17 @@ module Xmobar.App.Compile(recompile, trace, xmessage) where import Control.Monad.IO.Class -import Control.Monad.Fix (fix) -import Control.Exception.Extensible (try, bracket, SomeException(..)) +import Control.Exception.Extensible (bracket, SomeException(..)) import qualified Control.Exception.Extensible as E import Control.Monad (filterM, when) import Data.List ((\\)) -import Data.Maybe (isJust) import System.FilePath((), takeExtension) import System.IO import System.Directory import System.Process import System.Exit -import System.Posix.Process(executeFile, forkProcess, getAnyProcessStatus) +import System.Posix.Process(executeFile, forkProcess) import System.Posix.Types(ProcessID) -import System.Posix.Signals isExecutable :: FilePath -> IO Bool isExecutable f = @@ -144,14 +141,12 @@ recompile confDir dataDir execName force verb = liftIO $ do else shouldRecompile verb src bin lib if sc then do - uninstallSignalHandlers status <- bracket (openFile err WriteMode) hClose $ \errHandle -> waitForProcess =<< if useScript then runScript script bin confDir errHandle else runGHC bin confDir errHandle - installSignalHandlers if status == ExitSuccess then trace verb "Xmobar recompilation process exited with success!" else do @@ -174,21 +169,3 @@ recompile confDir dataDir execName force verb = liftIO $ do ++ ["-o", bin] runGHC bin = runProc "ghc" (opts bin) runScript script bin = runProc script [bin] - --- | Ignore SIGPIPE to avoid termination when a pipe is full, and SIGCHLD to --- avoid zombie processes, and clean up any extant zombie processes. -installSignalHandlers :: MonadIO m => m () -installSignalHandlers = liftIO $ do - installHandler openEndedPipe Ignore Nothing - installHandler sigCHLD Ignore Nothing - (try :: IO a -> IO (Either SomeException a)) - $ fix $ \more -> do - x <- getAnyProcessStatus False False - when (isJust x) more - return () - -uninstallSignalHandlers :: MonadIO m => m () -uninstallSignalHandlers = liftIO $ do - installHandler openEndedPipe Default Nothing - installHandler sigCHLD Default Nothing - return () -- cgit v1.2.3