0 | module System.Systemd.Internal
2 | import Control.Monad.Elin
6 | import System.Posix.Errno
7 | import System.Posix.File
8 | import System.Posix.Socket
14 | export %foreign "C:sd_notify_with_fd,systemd-idris"
15 | prim__sdNotifyWithFd : Int -> String -> Bits64 -> AnyPtr -> Bits32 -> Int -> PrimIO Int
22 | envvariablename : String
31 | unsetEnvironment : IO ()
41 | sendBufWithFdTo : Socket AF_UNIX
46 | sendBufWithFdTo socket state socketaddress filedesc =
48 | prim__sdNotifyWithFd (cast {to=Int} $
fd $
cast {to=Fd} socket)
50 | (cast {to=Bits64} (strLength state))
51 | (ptr AF_UNIX socketaddress)
53 | (cast {to=Int} (fd filedesc))
56 | notifyWithFd_ : Bool
60 | notifyWithFd_ unset_env state fd =
61 | case !(runElinIO $
notifyImpl state fd) of
63 | when unset_env unsetEnvironment
68 | when unset_env unsetEnvironment
72 | isValidPath : String
75 | (length path >= 2) &&
76 | (isPrefixOf "@" path || isPrefixOf "/" path)
79 | -> Elin World [Errno] ()
80 | notifyImpl state fd = do
81 | True <- pure $
state /= ""
84 | Just socketpath <- liftIO $
getEnv envvariablename
87 | True <- pure $
isValidPath socketpath
90 | let socketpath' = case fastUnpack socketpath of
101 | socketfd <- socket AF_UNIX
103 | srv <- runIO ( sockaddrUn socketpath
105 | Just socket' <- pure fd
114 | sendBufWithFdTo socketfd