Return fifo paths from Shim

This allows attach of existing fifos to be done without any information
stored on the client side.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-06-01 13:36:44 -07:00
parent 43fb19e01c
commit 00734ab04a
16 changed files with 682 additions and 191 deletions

25
io.go
View File

@@ -1,6 +1,7 @@
package containerd
import (
"fmt"
"io"
"io/ioutil"
"os"
@@ -26,6 +27,8 @@ func (i *IO) Close() error {
type IOCreation func() (*IO, error)
type IOAttach func(*FifoSet) (*IO, error)
func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation {
return func() (*IO, error) {
paths, err := NewFifos()
@@ -52,11 +55,10 @@ func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation {
}
}
func WithIO(stdin io.Reader, stdout, stderr io.Writer, dir string) IOCreation {
return func() (*IO, error) {
paths, err := WithFifos(dir)
if err != nil {
return nil, err
func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach {
return func(paths *FifoSet) (*IO, error) {
if paths == nil {
return nil, fmt.Errorf("cannot attach to existing fifos")
}
i := &IO{
Terminal: false,
@@ -121,19 +123,6 @@ func NewFifos() (*FifoSet, error) {
}, nil
}
// WithFifos returns existing or creates new fifos inside an existing dir
func WithFifos(dir string) (*FifoSet, error) {
if err := os.MkdirAll(dir, 0700); err != nil {
return nil, err
}
return &FifoSet{
Dir: dir,
In: filepath.Join(dir, "stdin"),
Out: filepath.Join(dir, "stdout"),
Err: filepath.Join(dir, "stderr"),
}, nil
}
type FifoSet struct {
// Dir is the directory holding the task fifos
Dir string