0 | module System.Systemd.Daemon.Fd
2 | import public System.Systemd.Internal
4 | import Control.Monad.Elin
9 | import System.Posix.Errno
10 | import System.Posix.File
11 | import System.Posix.Process
12 | import System.Posix.Socket
28 | notifyWithFd unset_env state sock =
29 | notifyWithFd_ unset_env
49 | storeFdWithName : Fd
52 | storeFdWithName fd name =
54 | ("FDSTORE=1\nFDNAME=" ++ name)
66 | getActivatedSockets : IO (Maybe (List Fd))
67 | getActivatedSockets = do
68 | Right res <- runElinIO getActivatedSockets'
75 | getActivatedSockets' : Elin World [Errno] (Maybe (List Fd))
76 | getActivatedSockets' = do
77 | Just listenpid <- liftIO $
getEnv "LISTEN_PID"
80 | Just listenfds <- liftIO $
getEnv "LISTEN_FDS"
84 | True <- pure $
(cast {to=Int32} listenpid) == mypid
87 | let fds = map (cast {to=Bits32})
88 | [fdstart .. (fdstart + ((cast {to=Int} listenfds) - 1))]
91 | addFlags fd O_NONBLOCK
100 | getActivatedSocketsWithNames : IO (Maybe (List (Fd, String)))
101 | getActivatedSocketsWithNames = do
102 | Right res <- runElinIO getActivatedSocketsWithNames'
109 | getActivatedSocketsWithNames' : Elin World [Errno] (Maybe (List (Fd, String)))
110 | getActivatedSocketsWithNames' = do
111 | Just listenfdnames <- liftIO $
getEnv "LISTEN_FDNAMES"
114 | let listenfdnames' = forget $
115 | split (== ':') listenfdnames
116 | Just nonblockfds <- liftIO getActivatedSockets
119 | True <- pure $
length nonblockfds == length listenfdnames'