Merge pull request #1205 from krallin/aggresively-close-netlink-cgroup-fds

Netlink: aggressively close cgroup fds
This commit is contained in:
Tim St. Clair 2016-04-13 15:22:05 -07:00
commit 4b1ef4733a
2 changed files with 6 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"os"
"syscall"
info "github.com/google/cadvisor/info/v1"
@ -219,10 +220,10 @@ func verifyHeader(msg syscall.NetlinkMessage) error {
// Get load stats for a task group.
// 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.
func getLoadStats(id uint16, fd uintptr, conn *Connection) (info.LoadStats, error) {
msg := prepareCmdMessage(id, fd)
func getLoadStats(id uint16, cfd *os.File, conn *Connection) (info.LoadStats, error) {
msg := prepareCmdMessage(id, cfd.Fd())
err := conn.WriteMessage(msg.toRawMsg())
if err != nil {
return info.LoadStats{}, err

View File

@ -66,11 +66,12 @@ func (self *NetlinkReader) GetCpuLoad(name string, path string) (info.LoadStats,
}
cfd, err := os.Open(path)
defer cfd.Close()
if err != nil {
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 {
return info.LoadStats{}, err
}