From 599fa1f9ffe03d123396e7027d1d93ae35c62cdb Mon Sep 17 00:00:00 2001 From: Sjon Hortensius Date: Sun, 6 Dec 2015 14:09:38 +0100 Subject: [PATCH] 2 Bugfixes plus minor readability fix in main * correct type of Cgroup.g * fix GetAllControllers, ECGEOF is indicator of end already reached so don't append cd again --- cg.go | 14 ++++++++------ main.go | 20 ++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cg.go b/cg.go index a829a5c..12f8663 100644 --- a/cg.go +++ b/cg.go @@ -21,7 +21,7 @@ Structure describing one or more control groups. The structure is opaque to applications. */ type Cgroup struct { - g *C.struct_group + g *C.struct_cgroup } func NewCgroup(name string) Cgroup { @@ -482,12 +482,14 @@ func GetAllControllers() (controllers []ControllerData, err error) { controllers = append(controllers, fromCControllerData(cd)) for { err = _err(C.cgroup_get_all_controller_next(&handle, &cd)) - if err != nil && err != ECGEOF { + if err != nil { + if err == ECGEOF { + break + } + return controllers, err - } - controllers = append(controllers, fromCControllerData(cd)) - if err == ECGEOF { - break + } else { + controllers = append(controllers, fromCControllerData(cd)) } } return controllers, nil diff --git a/main.go b/main.go index 4296378..8bcbf69 100644 --- a/main.go +++ b/main.go @@ -1,34 +1,30 @@ // cmpout - // +build ignore package main import ( - "." + "." "fmt" ) func main() { cgroup.Init() - fmt.Println(cgroup.DeleteIgnoreMigration) - fmt.Println(cgroup.DeleteIgnoreMigration|cgroup.DeleteEmptyOnly) - g := cgroup.NewCgroup("foo") - c := g.AddController("bar") - fmt.Printf("%#v\n", c) - c = g.GetController("bar") - fmt.Printf("%#v\n", c) + g := cgroup.NewCgroup("foo") + c := g.AddController("bar") + fmt.Printf("%#v\n", c) + c = g.GetController("bar") + fmt.Printf("%#v\n", c) - g.SetPermissions(cgroup.Mode(0777), cgroup.Mode(0777), cgroup.Mode(0777)) + g.SetPermissions(cgroup.Mode(0777), cgroup.Mode(0777), cgroup.Mode(0777)) - //fmt.Println(cgroup.GetSubSysMountPoint("cpu")) ctls, err := cgroup.GetAllControllers() if err != nil { fmt.Println(err) return } for i := range ctls { - fmt.Println(ctls[i]) + fmt.Printf("Hierarchy=%d Enabled=%d NumCgroups=%d Name=%s\n", ctls[i].Hierarchy, ctls[i].Enabled, ctls[i].NumCgroups, ctls[i].Name) } }