Copyright | (c) Maxime Henrion 2009-2010 |
---|---|
License | see LICENSE |
Maintainer | mhenrion@gmail.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
This module allows access to the BSD sysctl(3) interface via the Haskell FFI.
Convenience functions to read and write the usual sysctl types are provided,
as well as more advanced functions to handle binary values given a suitable
Storable
instance. It is also possible to retrieve data whose size changes
at runtime with the sysctlPeekArray
function.
On some platforms, there are sysctl nodes that accept parameters via
additional components in the OID (see for instance the "kern.proc.pid"
sysctl described in sysctl(3) on FreeBSD). The sysctlNameToOidArgs
function makes it easy to query such nodes as well.
Nodes may be queried either by their OID as a list of integers, by their binary OID for maximum speed, or by their names on platforms that support it.
- class SysctlKey k
- data OID
- sysctlPrepareOid :: [Int32] -> IO OID
- sysctlExtractOid :: OID -> IO [Int32]
- sysctlReadInt :: SysctlKey k => k -> IO Int32
- sysctlReadUInt :: SysctlKey k => k -> IO Word32
- sysctlReadLong :: SysctlKey k => k -> IO Int64
- sysctlReadULong :: SysctlKey k => k -> IO Word64
- sysctlReadQuad :: SysctlKey k => k -> IO Int64
- sysctlReadUQuad :: SysctlKey k => k -> IO Word64
- sysctlReadString :: SysctlKey k => k -> IO String
- sysctlPeek :: forall k a. (SysctlKey k, Storable a) => k -> IO a
- sysctlPeekArray :: forall k a. (SysctlKey k, Storable a) => k -> IO [a]
- sysctlWriteInt :: SysctlKey k => k -> Int32 -> IO ()
- sysctlWriteUInt :: SysctlKey k => k -> Word32 -> IO ()
- sysctlWriteLong :: SysctlKey k => k -> Int64 -> IO ()
- sysctlWriteULong :: SysctlKey k => k -> Word64 -> IO ()
- sysctlWriteQuad :: SysctlKey k => k -> Int64 -> IO ()
- sysctlWriteUQuad :: SysctlKey k => k -> Word64 -> IO ()
- sysctlWriteString :: SysctlKey k => k -> String -> IO ()
- sysctlPoke :: (SysctlKey k, Storable a) => k -> a -> IO ()
The data types
The class of types that can be used to identify a sysctl node.
withKey
An efficient representation of a sysctl OID
for maximum performance.
OID creation and extraction
Basic reading functions
sysctlReadInt :: SysctlKey k => k -> IO Int32 Source #
Read a signed integer from a sysctl (the C int type).
sysctlReadUInt :: SysctlKey k => k -> IO Word32 Source #
Read an unsigned integer from a sysctl (the C unsigned int type).
sysctlReadLong :: SysctlKey k => k -> IO Int64 Source #
Read a signed long integer from a sysctl (the C long type).
sysctlReadULong :: SysctlKey k => k -> IO Word64 Source #
Read an unsigned long integer from a sysctl (the C unsigned long type).
sysctlReadUQuad :: SysctlKey k => k -> IO Word64 Source #
Read an unsigned 64-bit integer from a sysctl.
sysctlReadString :: SysctlKey k => k -> IO String Source #
Read a string from a sysctl. If the string can possibly change with
time, use sysctlPeekArray
for characters instead.
Advanced reading functions
sysctlPeek :: forall k a. (SysctlKey k, Storable a) => k -> IO a Source #
Read a storable value from a sysctl node. This is useful to read binary values such as C structures, otherwise the ad-hoc reading functions should be used instead.
sysctlPeekArray :: forall k a. (SysctlKey k, Storable a) => k -> IO [a] Source #
Like sysctlPeek
, but allows to retrieve a list of elements whose
length can possibly change at runtime.
Basic writing functions
sysctlWriteInt :: SysctlKey k => k -> Int32 -> IO () Source #
Write a signed integer to a sysctl (the C int type).
sysctlWriteUInt :: SysctlKey k => k -> Word32 -> IO () Source #
Write an unsigned integer to a sysctl (the C unsigned int type).
sysctlWriteLong :: SysctlKey k => k -> Int64 -> IO () Source #
Write a signed long integer to a sysctl (the C long type).
sysctlWriteULong :: SysctlKey k => k -> Word64 -> IO () Source #
Write an unsigned long integer to a sysctl (the C unsigned long type).
sysctlWriteQuad :: SysctlKey k => k -> Int64 -> IO () Source #
Write a signed 64-bit integer to a sysctl.
sysctlWriteUQuad :: SysctlKey k => k -> Word64 -> IO () Source #
Write an unsigned 64-bit integer to a sysctl.