mirror of
https://github.com/vbatts/go-cgroup.git
synced 2025-01-15 10:10:09 +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
12
cg.go
12
cg.go
|
@ -21,7 +21,7 @@ Structure describing one or more control groups. The structure is opaque to
|
||||||
applications.
|
applications.
|
||||||
*/
|
*/
|
||||||
type Cgroup struct {
|
type Cgroup struct {
|
||||||
g *C.struct_group
|
g *C.struct_cgroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCgroup(name string) Cgroup {
|
func NewCgroup(name string) Cgroup {
|
||||||
|
@ -482,13 +482,15 @@ func GetAllControllers() (controllers []ControllerData, err error) {
|
||||||
controllers = append(controllers, fromCControllerData(cd))
|
controllers = append(controllers, fromCControllerData(cd))
|
||||||
for {
|
for {
|
||||||
err = _err(C.cgroup_get_all_controller_next(&handle, &cd))
|
err = _err(C.cgroup_get_all_controller_next(&handle, &cd))
|
||||||
if err != nil && err != ECGEOF {
|
if err != nil {
|
||||||
return controllers, err
|
|
||||||
}
|
|
||||||
controllers = append(controllers, fromCControllerData(cd))
|
|
||||||
if err == ECGEOF {
|
if err == ECGEOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return controllers, err
|
||||||
|
} else {
|
||||||
|
controllers = append(controllers, fromCControllerData(cd))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return controllers, nil
|
return controllers, nil
|
||||||
}
|
}
|
||||||
|
|
6
main.go
6
main.go
|
@ -1,5 +1,4 @@
|
||||||
// cmpout
|
// cmpout
|
||||||
|
|
||||||
// +build ignore
|
// +build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
@ -11,8 +10,6 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cgroup.Init()
|
cgroup.Init()
|
||||||
fmt.Println(cgroup.DeleteIgnoreMigration)
|
|
||||||
fmt.Println(cgroup.DeleteIgnoreMigration|cgroup.DeleteEmptyOnly)
|
|
||||||
|
|
||||||
g := cgroup.NewCgroup("foo")
|
g := cgroup.NewCgroup("foo")
|
||||||
c := g.AddController("bar")
|
c := g.AddController("bar")
|
||||||
|
@ -22,13 +19,12 @@ func main() {
|
||||||
|
|
||||||
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()
|
ctls, err := cgroup.GetAllControllers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := range ctls {
|
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