diff options
| author | tv <tv@shackspace.de> | 2014-11-04 00:00:40 +0100 | 
|---|---|---|
| committer | tv <tv@shackspace.de> | 2014-11-04 00:00:40 +0100 | 
| commit | a1aa9ddd72dfdec47399f29319f821f542906365 (patch) | |
| tree | b235d966ff561a649fb873072d5edd5969c082a6 /src/CGroup | |
| parent | 0f447cd62836a5f5b29b8e14263fde89f446f52b (diff) | |
mv **.hs src/
Diffstat (limited to 'src/CGroup')
| -rw-r--r-- | src/CGroup/Types.hs | 51 | 
1 files changed, 51 insertions, 0 deletions
| diff --git a/src/CGroup/Types.hs b/src/CGroup/Types.hs new file mode 100644 index 0000000..98422f3 --- /dev/null +++ b/src/CGroup/Types.hs @@ -0,0 +1,51 @@ +-- | +-- Module:      CGroup.Types +-- Copyright:   (c) 2014 Tomislav Viljetić +-- License:     BSD3 +-- Maintainer:  Tomislav Viljetić <tomislav@viljetic.de> +-- + +module CGroup.Types +    ( +    -- * CGroup +      CGroup +    , cgroup +    , cgroupPath +    -- * Other types +    , ProcessID +    ) where + +import Data.Monoid +import qualified System.FilePath as FP + + +-- | A 'CGroup' is defined by two 'FilePath's, a mount point and a cgroup +-- name.  The mount point specifies where the cgroup hierarchy is mounted. +-- The cgroup name is a directory, relative to the mount point. +data CGroup = CGroup { mountPoint, cgroupName :: FilePath } +  deriving Show + + +-- | Smart constructor. Takes a mount point and a cgroup name. +-- It will return 'Nothing' if the cgroup could point outside the mount point, +-- i.e. if the cgroup name is an absolute path, or contains @".."@. +cgroup :: FilePath -> FilePath -> Maybe CGroup +cgroup mp0 cgn0 +    | ".." `elem` parts = Nothing +    | FP.isAbsolute cgn = Nothing +    | otherwise = Just CGroup { mountPoint = mp, cgroupName = cgn } +  where +    mp = normaliseMountPoint mp0 +    cgn = normaliseCGroupName cgn0 +    parts = FP.splitDirectories cgn +    normaliseMountPoint = FP.addTrailingPathSeparator . FP.normalise +    normaliseCGroupName = FP.dropTrailingPathSeparator . FP.normalise + + +-- | Path of a cgroup's tasks file. +cgroupPath :: CGroup -> FilePath +cgroupPath CGroup { mountPoint = mp, cgroupName = cgn } = +    mp <> cgn + + +type ProcessID = Int | 
