Add close stdin
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
277cc920a4
commit
a42eb9fd63
12 changed files with 358 additions and 157 deletions
|
@ -19,6 +19,7 @@ const (
|
|||
SignalEventType EventType = "signal"
|
||||
AddProcessEventType EventType = "addProcess"
|
||||
UpdateContainerEventType EventType = "updateContainer"
|
||||
UpdateProcessEventType EventType = "updateProcess"
|
||||
CreateCheckpointEventType EventType = "createCheckpoint"
|
||||
DeleteCheckpointEventType EventType = "deleteCheckpoint"
|
||||
StatsEventType EventType = "events"
|
||||
|
@ -61,6 +62,10 @@ type Event struct {
|
|||
Err chan error
|
||||
StartResponse chan StartResponse
|
||||
Stats chan interface{}
|
||||
CloseStdin bool
|
||||
ResizeTty bool
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
type Handler interface {
|
||||
|
|
|
@ -66,6 +66,7 @@ func New(stateDir string, tasks chan *StartTask, oom bool) (*Supervisor, error)
|
|||
StatsEventType: &StatsEvent{s},
|
||||
UnsubscribeStatsEventType: &UnsubscribeStatsEvent{s},
|
||||
StopStatsEventType: &StopStatsEvent{s},
|
||||
UpdateProcessEventType: &UpdateProcessEvent{s},
|
||||
}
|
||||
go s.exitHandler()
|
||||
if err := s.restore(); err != nil {
|
||||
|
|
|
@ -26,18 +26,41 @@ func (h *UpdateEvent) Handle(e *Event) error {
|
|||
return ErrUnknownContainerStatus
|
||||
}
|
||||
}
|
||||
if e.Signal != nil {
|
||||
// signal the pid1/main process of the container
|
||||
processes, err := container.Processes()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateProcessEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
func (h *UpdateProcessEvent) Handle(e *Event) error {
|
||||
i, ok := h.s.containers[e.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
processes, err := i.container.Processes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var process runtime.Process
|
||||
for _, p := range processes {
|
||||
if p.ID() == e.Pid {
|
||||
process = p
|
||||
break
|
||||
}
|
||||
}
|
||||
if process == nil {
|
||||
return ErrProcessNotFound
|
||||
}
|
||||
if e.CloseStdin {
|
||||
if err := process.CloseStdin(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, p := range processes {
|
||||
if p.ID() == runtime.InitProcessID {
|
||||
return p.Signal(e.Signal)
|
||||
}
|
||||
}
|
||||
if e.Width > 0 || e.Height > 0 {
|
||||
if err := process.Resize(e.Width, e.Height); err != nil {
|
||||
return err
|
||||
}
|
||||
return ErrProcessNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue