I'm writing a Haskell program whose sole purpose is to execute another (non-Haskell) program, after gathering some info to determine what arguments that program should be executed with.
Replacing a running Haskell process is easy enough using executeFile, but I'm wondering if there's a way to ensure the Haskell program properly cleans up after itself before it's replaced.
For example, Control.Exception.finally is normally useful to ensure cleanup actions are performed even if an exception occurs, but it will have no effect if we exec a whole different process:
module Main (main) where
import Control.Exception (finally)
import System.Posix.Process (executeFile)
main = finally (do putStrLn "opening file descriptors"
putStrLn "writing temporary files"
executeFile "ls" True [] Nothing)
(putStrLn "cleaning up")
The above example will never print "cleaning up".
Is there a recommended way to perform such a maneuver "cleanly"?