Merge pull request #424 from dqminh/fix-generic-error

Fix panic when genericError constructor gets nil error
This commit is contained in:
Mrunal Patel 2015-03-03 20:11:37 -08:00
commit 903680701a
3 changed files with 15 additions and 8 deletions

View File

@ -212,7 +212,7 @@ func (c *linuxContainer) Destroy() error {
return err return err
} }
if status != Destroyed { if status != Destroyed {
return newGenericError(nil, ContainerNotStopped) return newGenericError(fmt.Errorf("container is not destroyed"), ContainerNotStopped)
} }
if !c.config.Namespaces.Contains(configs.NEWPID) { if !c.config.Namespaces.Contains(configs.NEWPID) {
if err := killCgroupProcesses(c.cgroupManager); err != nil { if err := killCgroupProcesses(c.cgroupManager); err != nil {

View File

@ -25,26 +25,32 @@ func newGenericError(err error, c ErrorCode) Error {
if le, ok := err.(Error); ok { if le, ok := err.(Error); ok {
return le return le
} }
return &genericError{ gerr := &genericError{
Timestamp: time.Now(), Timestamp: time.Now(),
Err: err, Err: err,
Message: err.Error(),
ECode: c, ECode: c,
Stack: stacktrace.Capture(1), Stack: stacktrace.Capture(1),
} }
if err != nil {
gerr.Message = err.Error()
}
return gerr
} }
func newSystemError(err error) Error { func newSystemError(err error) Error {
if le, ok := err.(Error); ok { if le, ok := err.(Error); ok {
return le return le
} }
return &genericError{ gerr := &genericError{
Timestamp: time.Now(), Timestamp: time.Now(),
Err: err, Err: err,
ECode: SystemError, ECode: SystemError,
Message: err.Error(),
Stack: stacktrace.Capture(1), Stack: stacktrace.Capture(1),
} }
if err != nil {
gerr.Message = err.Error()
}
return gerr
} }
type genericError struct { type genericError struct {

View File

@ -1,6 +1,7 @@
package libcontainer package libcontainer
import ( import (
"fmt"
"io" "io"
"os" "os"
) )
@ -46,7 +47,7 @@ type Process struct {
// Wait releases any resources associated with the Process // Wait releases any resources associated with the Process
func (p Process) Wait() (*os.ProcessState, error) { func (p Process) Wait() (*os.ProcessState, error) {
if p.ops == nil { if p.ops == nil {
return nil, newGenericError(nil, ProcessNotExecuted) return nil, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
} }
return p.ops.wait() return p.ops.wait()
} }
@ -54,7 +55,7 @@ func (p Process) Wait() (*os.ProcessState, error) {
// Pid returns the process ID // Pid returns the process ID
func (p Process) Pid() (int, error) { func (p Process) Pid() (int, error) {
if p.ops == nil { if p.ops == nil {
return -1, newGenericError(nil, ProcessNotExecuted) return -1, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
} }
return p.ops.pid(), nil return p.ops.pid(), nil
} }
@ -62,7 +63,7 @@ func (p Process) Pid() (int, error) {
// Signal sends a signal to the Process. // Signal sends a signal to the Process.
func (p Process) Signal(sig os.Signal) error { func (p Process) Signal(sig os.Signal) error {
if p.ops == nil { if p.ops == nil {
return newGenericError(nil, ProcessNotExecuted) return newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
} }
return p.ops.signal(sig) return p.ops.signal(sig)
} }