-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ffd1b88
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
dist | ||
dist-* | ||
cabal-dev | ||
*.o | ||
*.hi | ||
*.chi | ||
*.chs.h | ||
*.dyn_o | ||
*.dyn_hi | ||
.hpc | ||
.hsenv | ||
.cabal-sandbox/ | ||
cabal.sandbox.config | ||
*.prof | ||
*.aux | ||
*.hp | ||
*.eventlog | ||
.stack-work/ | ||
cabal.project.local | ||
cabal.project.local~ | ||
.HTF/ | ||
.ghc.environment.* | ||
stack.yaml | ||
*.swm | ||
*.swo | ||
*.swp | ||
test_results/** | ||
*.dump-simpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright (c) 2023, Andrew Martin | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Andrew Martin nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Linux.Systemd | ||
( listenFds | ||
, isSocket | ||
) where | ||
|
||
import Foreign.C.Types (CInt(..)) | ||
import System.Posix.Types (Fd(..)) | ||
import Foreign.C.Error (Errno,getErrno) | ||
import Posix.Socket (Type(..),Family(..)) | ||
|
||
foreign import ccall unsafe "systemd/sd-daemon.h sd_listen_fds" | ||
c_listenFds :: CInt -> IO CInt | ||
|
||
foreign import ccall unsafe "systemd/sd-daemon.h sd_is_socket" | ||
c_isSocket :: Fd -> Family -> Type -> CInt -> IO CInt | ||
|
||
-- | Check for file descriptors passed by the system manager. Returns | ||
-- the number of received file descriptors. If no file descriptors | ||
-- have been received, zero is returned. | ||
listenFds :: | ||
CInt -- ^ unset environment (non-zero unsets @LISTEN_FDS@, @LISTEN_PID@, and @LISTEN_FDNAMES@) | ||
-> IO (Either Errno CInt) | ||
listenFds a = c_listenFds a >>= errorsFromInt | ||
|
||
isSocket :: | ||
Fd -- ^ File descriptor | ||
-> Family -- ^ Socket family | ||
-> Type -- ^ Socket type | ||
-> CInt -- ^ Positive: require listen mode. Zero: require non-listening mode. | ||
-> IO (Either Errno CInt) | ||
isSocket a b c d = c_isSocket a b c d >>= errorsFromInt | ||
|
||
errorsFromInt :: CInt -> IO (Either Errno CInt) | ||
errorsFromInt r = if r >= 0 | ||
then pure (Right r) | ||
else fmap Left getErrno |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cabal-version: 2.2 | ||
name: systemd-api | ||
version: 0.1.0.0 | ||
synopsis: systemd bindings | ||
description: Bindings to various systemd functions | ||
homepage: https://github.com/byteverse/systemd-api | ||
license: BSD-3-Clause | ||
license-file: LICENSE | ||
author: Andrew Martin | ||
maintainer: [email protected] | ||
copyright: 2023 Andrew Martin | ||
category: System | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: | ||
Linux.Systemd | ||
build-depends: | ||
, base >=4.16.3 && <5 | ||
, byte-order >= 0.1.2 && <0.2 | ||
, byteslice >= 0.2.10 && <0.3 | ||
, primitive >= 0.7 && <0.10 | ||
, text-short >=0.1.5 | ||
, posix-api >=0.5 | ||
hs-source-dirs: src | ||
default-language: Haskell2010 | ||
ghc-options: -Wall -O2 | ||
extra-libraries: systemd | ||
build-tool-depends: hsc2hs:hsc2hs >= 0.68.5 |