Add LoadProcess api to Task
Fixes #1374 This adds a `LoadProcess` api to load existing exec'd processes from a task. It allows reattaching of IO and waiting on the process. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
30
container.go
30
container.go
@@ -245,19 +245,7 @@ func (c *container) loadTask(ctx context.Context, ioAttach IOAttach) (Task, erro
|
||||
}
|
||||
var i IO
|
||||
if ioAttach != nil {
|
||||
// get the existing fifo paths from the task information stored by the daemon
|
||||
paths := &FIFOSet{
|
||||
Dir: getFifoDir([]string{
|
||||
response.Process.Stdin,
|
||||
response.Process.Stdout,
|
||||
response.Process.Stderr,
|
||||
}),
|
||||
In: response.Process.Stdin,
|
||||
Out: response.Process.Stdout,
|
||||
Err: response.Process.Stderr,
|
||||
Terminal: response.Process.Terminal,
|
||||
}
|
||||
if i, err = ioAttach(paths); err != nil {
|
||||
if i, err = attachExistingIO(response, ioAttach); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -270,6 +258,22 @@ func (c *container) loadTask(ctx context.Context, ioAttach IOAttach) (Task, erro
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func attachExistingIO(response *tasks.GetResponse, ioAttach IOAttach) (IO, error) {
|
||||
// get the existing fifo paths from the task information stored by the daemon
|
||||
paths := &FIFOSet{
|
||||
Dir: getFifoDir([]string{
|
||||
response.Process.Stdin,
|
||||
response.Process.Stdout,
|
||||
response.Process.Stderr,
|
||||
}),
|
||||
In: response.Process.Stdin,
|
||||
Out: response.Process.Stdout,
|
||||
Err: response.Process.Stderr,
|
||||
Terminal: response.Process.Terminal,
|
||||
}
|
||||
return ioAttach(paths)
|
||||
}
|
||||
|
||||
// getFifoDir looks for any non-empty path for a stdio fifo
|
||||
// and returns the dir for where it is located
|
||||
func getFifoDir(paths []string) string {
|
||||
|
||||
Reference in New Issue
Block a user