diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 4f1b379..cdb2b35 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -25,6 +25,7 @@ var ( type subsystem interface { Set(*data) error + Remove(*data) error } type data struct { @@ -94,24 +95,8 @@ func (raw *data) join(subsystem string) (string, error) { } func (raw *data) Cleanup() error { - get := func(subsystem string) string { - path, _ := raw.path(subsystem) - return path - } - - for _, path := range []string{ - get("memory"), - get("devices"), - get("cpu"), - get("cpuset"), - get("cpuacct"), - get("blkio"), - get("perf_event"), - get("freezer"), - } { - if path != "" { - os.RemoveAll(path) - } + for _, sys := range subsystems { + sys.Remove(raw) } return nil } @@ -119,3 +104,13 @@ func (raw *data) Cleanup() error { func writeFile(dir, file, data string) error { return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700) } + +func removePath(p string, err error) error { + if err != nil { + return err + } + if p != "" { + return os.RemoveAll(p) + } + return nil +} diff --git a/cgroups/fs/blkio.go b/cgroups/fs/blkio.go index f0096f8..48dcf1a 100644 --- a/cgroups/fs/blkio.go +++ b/cgroups/fs/blkio.go @@ -14,3 +14,7 @@ func (s *blkioGroup) Set(d *data) error { } return nil } + +func (s *blkioGroup) Remove(d *data) error { + return removePath(d.path("blkio")) +} diff --git a/cgroups/fs/cpu.go b/cgroups/fs/cpu.go index 33879ba..f458d79 100644 --- a/cgroups/fs/cpu.go +++ b/cgroups/fs/cpu.go @@ -21,3 +21,7 @@ func (s *cpuGroup) Set(d *data) error { } return nil } + +func (s *cpuGroup) Remove(d *data) error { + return removePath(d.path("cpu")) +} diff --git a/cgroups/fs/cpuacct.go b/cgroups/fs/cpuacct.go index 603b100..22dfb41 100644 --- a/cgroups/fs/cpuacct.go +++ b/cgroups/fs/cpuacct.go @@ -14,3 +14,7 @@ func (s *cpuacctGroup) Set(d *data) error { } return nil } + +func (s *cpuacctGroup) Remove(d *data) error { + return removePath(d.path("cpuacct")) +} diff --git a/cgroups/fs/cpuset.go b/cgroups/fs/cpuset.go index 5108365..3d3b15f 100644 --- a/cgroups/fs/cpuset.go +++ b/cgroups/fs/cpuset.go @@ -26,3 +26,7 @@ func (s *cpusetGroup) Set(d *data) error { } return nil } + +func (s *cpusetGroup) Remove(d *data) error { + return removePath(d.path("cpuset")) +} diff --git a/cgroups/fs/devices.go b/cgroups/fs/devices.go index 769df39..fc5d83b 100644 --- a/cgroups/fs/devices.go +++ b/cgroups/fs/devices.go @@ -59,3 +59,7 @@ func (s *devicesGroup) Set(d *data) error { } return nil } + +func (s *devicesGroup) Remove(d *data) error { + return removePath(d.path("devices")) +} diff --git a/cgroups/fs/freezer.go b/cgroups/fs/freezer.go index 51db689..05bc584 100644 --- a/cgroups/fs/freezer.go +++ b/cgroups/fs/freezer.go @@ -14,3 +14,7 @@ func (s *freezerGroup) Set(d *data) error { } return nil } + +func (s *freezerGroup) Remove(d *data) error { + return removePath(d.path("freezer")) +} diff --git a/cgroups/fs/memory.go b/cgroups/fs/memory.go index cf33d66..a098f21 100644 --- a/cgroups/fs/memory.go +++ b/cgroups/fs/memory.go @@ -39,3 +39,7 @@ func (s *memoryGroup) Set(d *data) error { } return nil } + +func (s *memoryGroup) Remove(d *data) error { + return removePath(d.path("memory")) +} diff --git a/cgroups/fs/perf_event.go b/cgroups/fs/perf_event.go index 2af6d7a..b5ec6c6 100644 --- a/cgroups/fs/perf_event.go +++ b/cgroups/fs/perf_event.go @@ -14,3 +14,7 @@ func (s *perfEventGroup) Set(d *data) error { } return nil } + +func (s *perfEventGroup) Remove(d *data) error { + return removePath(d.path("perf_event")) +}