Merge pull request #5383 from wzshiming/clean/process-io

move common code to pkg/process from runtime
This commit is contained in:
Michael Crosby 2021-04-20 14:40:12 -04:00 committed by GitHub
commit a3fe5c84c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 25 deletions

View File

@ -251,14 +251,6 @@ func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (_ runc.IO, err e
return nil, err return nil, err
} }
var args []string
for k, vs := range uri.Query() {
args = append(args, k)
if len(vs) > 0 {
args = append(args, vs[0])
}
}
var closers []func() error var closers []func() error
defer func() { defer func() {
if err == nil { if err == nil {
@ -289,12 +281,7 @@ func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (_ runc.IO, err e
} }
closers = append(closers, r.Close, w.Close) closers = append(closers, r.Close, w.Close)
cmd := exec.Command(uri.Path, args...) cmd := NewBinaryCmd(uri, id, ns)
cmd.Env = append(cmd.Env,
"CONTAINER_ID="+id,
"CONTAINER_NAMESPACE="+ns,
)
cmd.ExtraFiles = append(cmd.ExtraFiles, out.r, serr.r, w) cmd.ExtraFiles = append(cmd.ExtraFiles, out.r, serr.r, w)
// don't need to register this with the reaper or wait when // don't need to register this with the reaper or wait when
// running inside a shim // running inside a shim

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package runtime package process
import ( import (
"net/url" "net/url"

View File

@ -26,7 +26,7 @@ import (
"github.com/containerd/console" "github.com/containerd/console"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/pkg/process"
"github.com/containerd/fifo" "github.com/containerd/fifo"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -75,14 +75,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
return nil, err return nil, err
} }
cmd := runtime.NewBinaryCmd(uri, id, ns) cmd := process.NewBinaryCmd(uri, id, ns)
// In case of unexpected errors during logging binary start, close open pipes // In case of unexpected errors during logging binary start, close open pipes
var filesToClose []*os.File var filesToClose []*os.File
defer func() { defer func() {
if retErr != nil { if retErr != nil {
runtime.CloseFiles(filesToClose...) process.CloseFiles(filesToClose...)
} }
}() }()

View File

@ -28,7 +28,7 @@ import (
"github.com/containerd/console" "github.com/containerd/console"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/pkg/process"
"github.com/containerd/fifo" "github.com/containerd/fifo"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -63,15 +63,14 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
if err != nil { if err != nil {
return nil, err return nil, err
} }
cmd := process.NewBinaryCmd(uri, id, ns)
cmd := runtime.NewBinaryCmd(uri, id, ns)
// In case of unexpected errors during logging binary start, close open pipes // In case of unexpected errors during logging binary start, close open pipes
var filesToClose []*os.File var filesToClose []*os.File
defer func() { defer func() {
if retErr != nil { if retErr != nil {
runtime.CloseFiles(filesToClose...) process.CloseFiles(filesToClose...)
} }
}() }()

View File

@ -28,8 +28,8 @@ import (
"github.com/containerd/console" "github.com/containerd/console"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/pkg/stdio" "github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/runtime"
"github.com/containerd/fifo" "github.com/containerd/fifo"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -99,14 +99,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
return nil, err return nil, err
} }
cmd := runtime.NewBinaryCmd(uri, id, ns) cmd := process.NewBinaryCmd(uri, id, ns)
// In case of unexpected errors during logging binary start, close open pipes // In case of unexpected errors during logging binary start, close open pipes
var filesToClose []*os.File var filesToClose []*os.File
defer func() { defer func() {
if retErr != nil { if retErr != nil {
runtime.CloseFiles(filesToClose...) process.CloseFiles(filesToClose...)
} }
}() }()