bsd-sysctl-1.0.7: Access to the BSD sysctl(3) interface

Portabilityportable
Stabilitystable
Maintainermhenrion@gmail.com
Safe HaskellNone

System.BSD.Sysctl

Contents

Description

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.

Synopsis

The data types

class SysctlKey k

The class of types that can be used to identify a sysctl node.

data OID

An efficient representation of a sysctl OID for maximum performance.

Instances

OID creation and extraction

sysctlNameToOid :: String -> IO OID

Get the OID corresponding to a sysctl name.

sysctlNameToOidArgs :: String -> [Int32] -> IO OID

Like sysctlNameToOid, but allows to provide a list of additional integers to append to the OID, for specific sysctl nodes that support parameters this way.

sysctlPrepareOid :: [Int32] -> IO OID

Prepare an OID for later use.

sysctlExtractOid :: OID -> IO [Int32]

Extract the list of integers contained in an OID.

Basic reading functions

sysctlReadInt :: SysctlKey k => k -> IO Int32

Read a signed integer from a sysctl (the C int type).

sysctlReadUInt :: SysctlKey k => k -> IO Word32

Read an unsigned integer from a sysctl (the C unsigned int type).

sysctlReadLong :: SysctlKey k => k -> IO Int32

Read a signed long integer from a sysctl (the C long type).

sysctlReadULong :: SysctlKey k => k -> IO Word32

Read an unsigned long integer from a sysctl (the C unsigned long type).

sysctlReadQuad :: SysctlKey k => k -> IO Int64

Read a signed 64-bit integer from a sysctl.

sysctlReadUQuad :: SysctlKey k => k -> IO Word64

Read an unsigned 64-bit integer from a sysctl.

sysctlReadString :: SysctlKey k => k -> IO String

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

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]

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 ()

Write a signed integer to a sysctl (the C int type).

sysctlWriteUInt :: SysctlKey k => k -> Word32 -> IO ()

Write an unsigned integer to a sysctl (the C unsigned int type).

sysctlWriteLong :: SysctlKey k => k -> Int32 -> IO ()

Write a signed long integer to a sysctl (the C long type).

sysctlWriteULong :: SysctlKey k => k -> Word32 -> IO ()

Write an unsigned long integer to a sysctl (the C unsigned long type).

sysctlWriteQuad :: SysctlKey k => k -> Int64 -> IO ()

Write a signed 64-bit integer to a sysctl.

sysctlWriteUQuad :: SysctlKey k => k -> Word64 -> IO ()

Write an unsigned 64-bit integer to a sysctl.

sysctlWriteString :: SysctlKey k => k -> String -> IO ()

Write a string to a sysctl.

Advanced writing functions

sysctlPoke :: (SysctlKey k, Storable a) => k -> a -> IO ()

Write a storable value to a sysctl node. This is useful to write binary values such as C structures, otherwise the ad-hoc writing functions should be used instead.