Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Fix panic when genericError constructor gets nil error #424

Merged
merged 2 commits into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *linuxContainer) Destroy() error {
return err
}
if status != Destroyed {
return newGenericError(nil, ContainerNotStopped)
return newGenericError(fmt.Errorf("container is not destroyed"), ContainerNotStopped)
}
if !c.config.Namespaces.Contains(configs.NEWPID) {
if err := killCgroupProcesses(c.cgroupManager); err != nil {
Expand Down
14 changes: 10 additions & 4 deletions generic_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@ func newGenericError(err error, c ErrorCode) Error {
if le, ok := err.(Error); ok {
return le
}
return &genericError{
gerr := &genericError{
Timestamp: time.Now(),
Err: err,
Message: err.Error(),
ECode: c,
Stack: stacktrace.Capture(1),
}
if err != nil {
gerr.Message = err.Error()
}
return gerr
}

func newSystemError(err error) Error {
if le, ok := err.(Error); ok {
return le
}
return &genericError{
gerr := &genericError{
Timestamp: time.Now(),
Err: err,
ECode: SystemError,
Message: err.Error(),
Stack: stacktrace.Capture(1),
}
if err != nil {
gerr.Message = err.Error()
}
return gerr
}

type genericError struct {
Expand Down
7 changes: 4 additions & 3 deletions process.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package libcontainer

import (
"fmt"
"io"
"os"
)
Expand Down Expand Up @@ -46,23 +47,23 @@ type Process struct {
// Wait releases any resources associated with the Process
func (p Process) Wait() (*os.ProcessState, error) {
if p.ops == nil {
return nil, newGenericError(nil, ProcessNotExecuted)
return nil, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
}
return p.ops.wait()
}

// Pid returns the process ID
func (p Process) Pid() (int, error) {
if p.ops == nil {
return -1, newGenericError(nil, ProcessNotExecuted)
return -1, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
}
return p.ops.pid(), nil
}

// Signal sends a signal to the Process.
func (p Process) Signal(sig os.Signal) error {
if p.ops == nil {
return newGenericError(nil, ProcessNotExecuted)
return newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
}
return p.ops.signal(sig)
}
Expand Down