Skip to content

Commit a5ef75b

Browse files
committed
Add signal API to Container interface
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>
1 parent ce0a339 commit a5ef75b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

libcontainer/container.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package libcontainer
66

77
import (
8+
"os"
9+
810
"github.com/opencontainers/runc/libcontainer/configs"
911
)
1012

@@ -159,4 +161,10 @@ type Container interface {
159161
// errors:
160162
// Systemerror - System error.
161163
NotifyOOM() (<-chan struct{}, error)
164+
165+
// Signal sends the provided signal code to the container's initial process.
166+
//
167+
// errors:
168+
// Systemerror - System error.
169+
Signal(s os.Signal) error
162170
}

libcontainer/container_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ func (c *linuxContainer) Start(process *Process) error {
118118
return nil
119119
}
120120

121+
func (c *linuxContainer) Signal(s os.Signal) error {
122+
if err := c.initProcess.signal(s); err != nil {
123+
return newSystemError(err)
124+
}
125+
return nil
126+
}
127+
121128
func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProcess, error) {
122129
parentPipe, childPipe, err := newPipe()
123130
if err != nil {

libcontainer/restored_process.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ func (p *nonChildProcess) startTime() (string, error) {
106106
}
107107

108108
func (p *nonChildProcess) signal(s os.Signal) error {
109-
return newGenericError(fmt.Errorf("restored process cannot be signaled"), SystemError)
109+
proc, err := os.FindProcess(p.processPid)
110+
if err != nil {
111+
return err
112+
}
113+
return proc.Signal(s)
110114
}
111115

112116
func (p *nonChildProcess) externalDescriptors() []string {

0 commit comments

Comments
 (0)