Skip to content

Commit

Permalink
Use patterns for POSIX signals.
Browse files Browse the repository at this point in the history
  • Loading branch information
jumper149 committed Oct 17, 2022
1 parent 7bda33b commit 98717aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/homepage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ library
other-modules:
, Control.Monad.IO.Unlift.OrphanInstances
, Control.Monad.Logger.OrphanInstances
, System.Posix.Signals.Patterns
, Text.Blaze.Html5.Extra
hs-source-dirs: source/library

Expand Down
7 changes: 4 additions & 3 deletions server/source/library/Homepage/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Servant.API.Generic
import Servant.Server
import Servant.Server.Generic
import System.Posix.Signals
import System.Posix.Signals.Patterns

type API :: Type
type API = ToServantApi Routes
Expand All @@ -48,9 +49,9 @@ server = do
logWarn "Shutdown."
closeSocket
let installShutdownHandler sig = void $ installHandler sig (catchOnceShutdown sig) Nothing
installShutdownHandler sigHUP
installShutdownHandler sigINT
installShutdownHandler sigTERM
installShutdownHandler SIGHUP
installShutdownHandler SIGINT
installShutdownHandler SIGTERM
let settings = withShutdownHandler $ withPort defaultSettings

logInfo "Configure middleware."
Expand Down
26 changes: 26 additions & 0 deletions server/source/library/System/Posix/Signals/Patterns.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE PatternSynonyms #-}

module System.Posix.Signals.Patterns where

import System.Posix.Signals

-- Source: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/kill.html
-- Other signals are not defined by POSIX.

pattern SIGHUP :: Signal
pattern SIGHUP = 1

pattern SIGINT :: Signal
pattern SIGINT = 2

pattern SIGQUIT :: Signal
pattern SIGQUIT = 3

pattern SIGABRT :: Signal
pattern SIGABRT = 6

pattern SIGALRM :: Signal
pattern SIGALRM = 14

pattern SIGTERM :: Signal
pattern SIGTERM = 15

0 comments on commit 98717aa

Please sign in to comment.