Skip to content

Commit

Permalink
Add signal API to Container interface
Browse files Browse the repository at this point in the history
This adds a `Signal()` method to the container interface so that the
initial process can be signaled after a Load or operation.  It also
implements signaling the init process from a nonChildProcess.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Aug 4, 2015
1 parent ce0a339 commit a5ef75b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions libcontainer/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package libcontainer

import (
"os"

"github.com/opencontainers/runc/libcontainer/configs"
)

Expand Down Expand Up @@ -159,4 +161,10 @@ type Container interface {
// errors:
// Systemerror - System error.
NotifyOOM() (<-chan struct{}, error)

// Signal sends the provided signal code to the container's initial process.
//
// errors:
// Systemerror - System error.
Signal(s os.Signal) error
}
7 changes: 7 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func (c *linuxContainer) Start(process *Process) error {
return nil
}

func (c *linuxContainer) Signal(s os.Signal) error {
if err := c.initProcess.signal(s); err != nil {
return newSystemError(err)
}
return nil
}

func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProcess, error) {
parentPipe, childPipe, err := newPipe()
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion libcontainer/restored_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ func (p *nonChildProcess) startTime() (string, error) {
}

func (p *nonChildProcess) signal(s os.Signal) error {
return newGenericError(fmt.Errorf("restored process cannot be signaled"), SystemError)
proc, err := os.FindProcess(p.processPid)
if err != nil {
return err
}
return proc.Signal(s)
}

func (p *nonChildProcess) externalDescriptors() []string {
Expand Down

0 comments on commit a5ef75b

Please sign in to comment.