packages feed

linux-namespaces 0.1.3.1 → 0.2.0.0

raw patch · 3 files changed

+50/−4 lines, 3 filesdep ~unixPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: unix

API changes (from Hackage documentation)

+ System.Linux.Namespaces: Boottime :: Clock
+ System.Linux.Namespaces: CGroup :: Namespace
+ System.Linux.Namespaces: Monotonic :: Clock
+ System.Linux.Namespaces: Time :: Namespace
+ System.Linux.Namespaces: data Clock
+ System.Linux.Namespaces: instance GHC.Classes.Eq System.Linux.Namespaces.Clock
+ System.Linux.Namespaces: instance GHC.Read.Read System.Linux.Namespaces.Clock
+ System.Linux.Namespaces: instance GHC.Show.Show System.Linux.Namespaces.Clock
+ System.Linux.Namespaces: setClockOffset :: Clock -> EpochTime -> CLong -> IO ()

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+#### 0.2.0.0 *2024-11-29*++	* Add support for CGroup and time namespaces.+ #### 0.1.3.1 *2023-06-23*  	* Support building with `unix-2.8`.
System/Linux/Namespaces.hsc view
@@ -45,6 +45,10 @@     , writeUserMappings     , writeGroupMappings +    -- * Setting offsets for virtualized clocks+    , Clock(..)+    , setClockOffset+     -- * Example     -- $example     ) where@@ -54,7 +58,7 @@  import Foreign import Foreign.C-import System.Posix.Types (Fd(..), ProcessID, UserID, GroupID)+import System.Posix.Types (Fd(..), ProcessID, UserID, GroupID, EpochTime) import System.Posix.IO import System.Posix.Files (readSymbolicLink) import Control.Exception (bracket)@@ -70,7 +74,7 @@ --------------------------------------------------------------------------------  -- | Types of namespaces.-data Namespace = IPC | Network | Mount | PID | User | UTS+data Namespace = IPC | Network | Mount | PID | User | UTS | CGroup | Time   deriving (Show, Read, Eq, Bounded, Enum)  toCloneFlags :: Namespace -> CInt@@ -82,6 +86,8 @@         PID     -> (#const CLONE_NEWPID)         User    -> (#const CLONE_NEWUSER)         UTS     -> (#const CLONE_NEWUTS)+        CGroup  -> (#const CLONE_NEWCGROUP)+        Time    -> (#const CLONE_NEWTIME)  toProcName :: Namespace -> String toProcName ns =@@ -92,6 +98,8 @@         PID     -> "pid"         User    -> "user"         UTS     -> "uts"+        CGroup  -> "cgroup"+        Time    -> "time"  -- | Detach the process from one or more namespaces and move it to new -- ones. See the man page of @unshare(2)@ for more details.@@ -130,7 +138,11 @@         setNamespace fd (Just ns)   where     openFd' = ioeSetLoc "enterNamespace" $+#if MIN_VERSION_unix(2,8,0)         openFd path ReadOnly defaultFileFlags {nonBlock = True}+#else+        openFd path ReadOnly Nothing defaultFileFlags {nonBlock = True}+#endif     path = toProcPath (Just pid) ns  -- | A unique namespace id.@@ -213,9 +225,39 @@  -------------------------------------------------------------------------------- +-- | The virtualized clock whose offset is set+-- @time_namespaces(7)@ for more details.+data Clock = Monotonic | Boottime+  deriving (Show, Read, Eq)++-- | Set the offset for a virtualized clock. This can only be called before any+-- process has been created in the time namespace. This function requires+-- @\/proc@ to be mounted. See @time_namespaces(7)@ for more details.+setClockOffset+    :: Clock           -- ^ Specify the clock whose offset is set.+    -> EpochTime       -- ^ The seconds component of the offset. This value+                       -- can be negative.+    -> CLong           -- ^ The nanoseconds component of the offset. This+                       -- value must not be negative.+    -> IO ()+setClockOffset clock offsetSecs offsetNanosecs =+    ioeSetLoc "setClockOffset" $ do+        writeProcFile "/proc/self/timens_offsets" (C.pack s)+  where+    s = concat [clockId, " ", show offsetSecs, " ", show offsetNanosecs]+    clockId = case clock of+        Monotonic -> "monotonic"+        Boottime -> "boottime"++--------------------------------------------------------------------------------+ writeProcFile :: FilePath -> ByteString -> IO () writeProcFile path bs =+#if MIN_VERSION_unix(2,8,0)     bracket (openFd path WriteOnly defaultFileFlags) closeFd $ \fd ->+#else+    bracket (openFd path WriteOnly Nothing defaultFileFlags) closeFd $ \fd ->+#endif         S.useAsCStringLen bs $ \(ptr, nb) ->             fdWriteBuf fd (castPtr ptr) (fromIntegral nb) >> return () 
linux-namespaces.cabal view
@@ -1,5 +1,5 @@ name:                linux-namespaces-version:             0.1.3.1+version:             0.2.0.0 synopsis:            Work with linux namespaces: create new or enter existing ones description:   This library provides bindings to the @unshare(2)@ and @setns(2)@ linux@@ -23,7 +23,7 @@  library   exposed-modules:     System.Linux.Namespaces-  build-depends:       base >=4.6 && <5, unix >=2.8 && <3.0, bytestring >=0.10 && <1.0+  build-depends:       base >=4.6 && <5, unix >=2.6 && <3.0, bytestring >=0.10 && <1.0   build-tools:         hsc2hs   default-language:    Haskell2010   ghc-options:         -Wall