Merge pull request #321 from vmarmol/no-file

Don't get stats for cgroups that don't exist.
This commit is contained in:
Michael Crosby 2015-01-08 11:26:02 -08:00
commit d7dea0e925
2 changed files with 3 additions and 3 deletions

View File

@ -105,7 +105,7 @@ func GetStats(systemPaths map[string]string) (*cgroups.Stats, error) {
stats := cgroups.NewStats()
for name, path := range systemPaths {
sys, ok := subsystems[name]
if !ok {
if !ok || !cgroups.PathExists(path) {
continue
}
if err := sys.GetStats(path, stats); err != nil {

View File

@ -174,7 +174,7 @@ func ParseCgroupFile(subsystem string, r io.Reader) (string, error) {
return "", NewNotFoundError(subsystem)
}
func pathExists(path string) bool {
func PathExists(path string) bool {
if _, err := os.Stat(path); err != nil {
return false
}
@ -183,7 +183,7 @@ func pathExists(path string) bool {
func EnterPid(cgroupPaths map[string]string, pid int) error {
for _, path := range cgroupPaths {
if pathExists(path) {
if PathExists(path) {
if err := ioutil.WriteFile(filepath.Join(path, "cgroup.procs"),
[]byte(strconv.Itoa(pid)), 0700); err != nil {
return err