Merge pull request #638 from lizf-os/fix-check-cpu-shares
Avoid trying to access cpu.shares when it doesn't exist
This commit is contained in:
commit
107b7ed268
|
@ -304,6 +304,10 @@ func removePath(p string, err error) error {
|
|||
func CheckCpushares(path string, c int64) error {
|
||||
var cpuShares int64
|
||||
|
||||
if c == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fd, err := os.Open(filepath.Join(path, "cpu.shares"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -314,12 +318,11 @@ func CheckCpushares(path string, c int64) error {
|
|||
if err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
if c != 0 {
|
||||
if c > cpuShares {
|
||||
return fmt.Errorf("The maximum allowed cpu-shares is %d", cpuShares)
|
||||
} else if c < cpuShares {
|
||||
return fmt.Errorf("The minimum allowed cpu-shares is %d", cpuShares)
|
||||
}
|
||||
|
||||
if c > cpuShares {
|
||||
return fmt.Errorf("The maximum allowed cpu-shares is %d", cpuShares)
|
||||
} else if c < cpuShares {
|
||||
return fmt.Errorf("The minimum allowed cpu-shares is %d", cpuShares)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue