Add container attach support.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -19,12 +19,10 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
@@ -157,37 +155,6 @@ func getSandboxDevShm(sandboxRootDir string) string {
|
||||
return filepath.Join(sandboxRootDir, "shm")
|
||||
}
|
||||
|
||||
// prepareStreamingPipes prepares stream named pipe for container. returns nil
|
||||
// streaming handler if corresponding stream path is empty.
|
||||
func (c *criContainerdService) prepareStreamingPipes(ctx context.Context, stdin, stdout, stderr string) (
|
||||
i io.WriteCloser, o io.ReadCloser, e io.ReadCloser, retErr error) {
|
||||
pipes := map[string]io.ReadWriteCloser{}
|
||||
for t, stream := range map[string]struct {
|
||||
path string
|
||||
flag int
|
||||
}{
|
||||
"stdin": {stdin, syscall.O_WRONLY | syscall.O_CREAT | syscall.O_NONBLOCK},
|
||||
"stdout": {stdout, syscall.O_RDONLY | syscall.O_CREAT | syscall.O_NONBLOCK},
|
||||
"stderr": {stderr, syscall.O_RDONLY | syscall.O_CREAT | syscall.O_NONBLOCK},
|
||||
} {
|
||||
if stream.path == "" {
|
||||
continue
|
||||
}
|
||||
s, err := c.os.OpenFifo(ctx, stream.path, stream.flag, 0700)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("failed to open named pipe %q: %v",
|
||||
stream.path, err)
|
||||
}
|
||||
defer func(cl io.Closer) {
|
||||
if retErr != nil {
|
||||
cl.Close()
|
||||
}
|
||||
}(s)
|
||||
pipes[t] = s
|
||||
}
|
||||
return pipes["stdin"], pipes["stdout"], pipes["stderr"], nil
|
||||
}
|
||||
|
||||
// getNetworkNamespace returns the network namespace of a process.
|
||||
func getNetworkNamespace(pid uint32) string {
|
||||
return fmt.Sprintf(netNSFormat, pid)
|
||||
|
||||
Reference in New Issue
Block a user