Merge pull request #321 from vmarmol/no-file
Don't get stats for cgroups that don't exist.
This commit is contained in:
commit
d7dea0e925
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue