Merge pull request #1205 from krallin/aggresively-close-netlink-cgroup-fds
Netlink: aggressively close cgroup fds
This commit is contained in:
commit
4b1ef4733a
@ -18,6 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
@ -219,10 +220,10 @@ func verifyHeader(msg syscall.NetlinkMessage) error {
|
|||||||
|
|
||||||
// Get load stats for a task group.
|
// Get load stats for a task group.
|
||||||
// id: family id for taskstats.
|
// id: family id for taskstats.
|
||||||
// fd: fd to path to the cgroup directory under cpu hierarchy.
|
// cfd: open file to path to the cgroup directory under cpu hierarchy.
|
||||||
// conn: open netlink connection used to communicate with kernel.
|
// conn: open netlink connection used to communicate with kernel.
|
||||||
func getLoadStats(id uint16, fd uintptr, conn *Connection) (info.LoadStats, error) {
|
func getLoadStats(id uint16, cfd *os.File, conn *Connection) (info.LoadStats, error) {
|
||||||
msg := prepareCmdMessage(id, fd)
|
msg := prepareCmdMessage(id, cfd.Fd())
|
||||||
err := conn.WriteMessage(msg.toRawMsg())
|
err := conn.WriteMessage(msg.toRawMsg())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info.LoadStats{}, err
|
return info.LoadStats{}, err
|
||||||
|
@ -66,11 +66,12 @@ func (self *NetlinkReader) GetCpuLoad(name string, path string) (info.LoadStats,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfd, err := os.Open(path)
|
cfd, err := os.Open(path)
|
||||||
|
defer cfd.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info.LoadStats{}, fmt.Errorf("failed to open cgroup path %s: %q", path, err)
|
return info.LoadStats{}, fmt.Errorf("failed to open cgroup path %s: %q", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stats, err := getLoadStats(self.familyId, cfd.Fd(), self.conn)
|
stats, err := getLoadStats(self.familyId, cfd, self.conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info.LoadStats{}, err
|
return info.LoadStats{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user