Commit 543e859d authored by Iustin Pop's avatar Iustin Pop
Browse files

hbal: change handling of signal



Currently, hbal does a one-two signal handling, where the first signal
causes graceful termination, and the second one an immediate on (either
SIGINT or SIGTERM can be used, interchangeably). However, this poses a
timing problem: if two programs want to send a graceful termination
request, they cannot do that without careful coordination.

To fix this, we change to code to handle the signal separately: SIGINT
(^C) sends graceful termination, while SIGTERM sends immediate
termination. This should allow easier controlling of hbal.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 306cccd5
...@@ -189,22 +189,26 @@ execJobSet master nl il cref alljss@(js:jss) = do ...@@ -189,22 +189,26 @@ execJobSet master nl il cref alljss@(js:jss) = do
show x show x
hPutStrLn stderr "Aborting.") hPutStrLn stderr "Aborting.")
-- | Signal handler -- | Signal handler for graceful termination
handleSig :: IORef Int -> IO () hangleSigInt :: IORef Int -> IO ()
handleSig cref = do hangleSigInt cref = do
cnt <- atomicModifyIORef cref (\x -> let y = x + 1 writeIORef cref 1
in (y, y)) putStrLn ("Cancel request registered, will exit at" ++
when (cnt > 1) $ do " the end of the current job set...")
putStrLn "Double cancel request, exiting now..."
exitImmediately $ ExitFailure 1 -- | Signal handler for immediate termination
when (cnt > 0) $ putStrLn ("Cancel request registered, will exit at" ++ hangleSigTerm :: IORef Int -> IO ()
" the end of the current job set...") hangleSigTerm cref = do
-- update the cref to 2, just for consistency
writeIORef cref 2
putStrLn "Double cancel request, exiting now..."
exitImmediately $ ExitFailure 2
runJobSet :: String -> Node.List -> Instance.List -> [JobSet] -> IO () runJobSet :: String -> Node.List -> Instance.List -> [JobSet] -> IO ()
runJobSet master fin_nl il cmd_jobs = do runJobSet master fin_nl il cmd_jobs = do
cref <- newIORef 0 cref <- newIORef 0
mapM_ (\sig -> installHandler sig (Catch (handleSig cref)) Nothing) mapM_ (\(hnd, sig) -> installHandler sig (Catch (hnd cref)) Nothing)
[softwareTermination, keyboardSignal] [(hangleSigTerm, softwareTermination), (hangleSigInt, keyboardSignal)]
execJobSet master fin_nl il cref cmd_jobs execJobSet master fin_nl il cref cmd_jobs
-- | Main function. -- | Main function.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment