mirror of
https://github.com/vbatts/go-cgroup.git
synced 2025-01-14 17:50:08 +00:00
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
This commit is contained in:
parent
70e3da7eb3
commit
599fa1f9ff
2 changed files with 16 additions and 18 deletions
14
cg.go
14
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
|
||||
|
|
20
main.go
20
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue