From e0f851d91a75350fbf80695ef5704d2b49c2b05d Mon Sep 17 00:00:00 2001 From: Mladen Srdic Date: Tue, 17 Nov 2020 13:09:18 +0100 Subject: [PATCH 1/2] Update README.md Fixed AddOne.hs link. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f67fd2c..411e4f6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Example ------- Here's -[AddOne](https://github.com/scvalex/daemons/blob/master/AddOne.hs), a +[AddOne](https://github.com/scvalex/daemons/blob/master/examples/AddOne.hs), a simple daemon that waits for a number and responds with the incremented number. From 3cb08ef558882e795a171224cd949e9e93a1e4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Srdic=CC=81?= Date: Tue, 17 Nov 2020 20:14:56 +0100 Subject: [PATCH 2/2] Use sigTERM instead of sigQUIT. --- src/System/Posix/Daemon.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/System/Posix/Daemon.hs b/src/System/Posix/Daemon.hs index 774c9b4..cdd8634 100644 --- a/src/System/Posix/Daemon.hs +++ b/src/System/Posix/Daemon.hs @@ -67,7 +67,7 @@ import System.Posix.IO ( openFd, OpenMode(..), defaultFileFlags, closeFd , createFile, fdWrite, fdRead , LockRequest (..), setLock, waitToSetLock ) import System.Posix.Process ( getProcessID, forkProcess, createSession ) -import System.Posix.Signals ( Signal, signalProcess, sigQUIT, sigKILL ) +import System.Posix.Signals ( Signal, signalProcess, sigKILL, sigTERM ) -- | Where should the output (and input) of a daemon be redirected to? -- (we can't just leave it to the current terminal, because it may be @@ -110,7 +110,7 @@ runDetached maybePidFile redirection program = do ignore $ forkProcess $ do -- create a new session and make this process its leader; see -- setsid(2) - ignore $ createSession + ignore createSession -- fork second child ignore $ forkProcess $ do -- create the pidfile @@ -174,20 +174,18 @@ isRunning pidFile = do Nothing -> do pid' <- getProcessID return (read pid == pid') - Just _ -> do - return True - else do - return False + Just _ -> return True + else return False --- | Send 'sigQUIT' to the process recorded in the pidfile. This +-- | Send 'sigTERM' to the process recorded in the pidfile. This -- gives the process a chance to close cleanly. kill :: FilePath -> IO () -kill = signalProcessByFilePath sigQUIT +kill = signalProcessByFilePath sigTERM -- | Kill a process and wait for it to release its pidfile killAndWait :: FilePath -> IO () killAndWait pidFile = do - signalProcessByFilePath sigQUIT pidFile + signalProcessByFilePath sigTERM pidFile fd <- openFd pidFile ReadWrite Nothing defaultFileFlags waitToSetLock fd (WriteLock, AbsoluteSeek, 0, 0) closeFd fd