Skip to content

Commit

Permalink
bugfix: disable mux stdout and stderr if backend is not http
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <[email protected]>
  • Loading branch information
YaoZengzeng committed Apr 28, 2018
1 parent 3b6d1ed commit a337da8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ctrd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Client) ExecContainer(ctx context.Context, process *Process) error {
pStderr io.Writer = process.IO.Stderr
)

if !process.P.Terminal {
if !process.P.Terminal && !process.IO.MuxDisabled {
pStdout = stdcopy.NewStdWriter(pStdout, stdcopy.Stdout)
pStderr = stdcopy.NewStdWriter(pStderr, stdcopy.Stderr)
}
Expand Down
11 changes: 9 additions & 2 deletions daemon/containerio/container_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ type IO struct {
Stdout *ContainerIO
Stderr *ContainerIO
Stdin *ContainerIO

// For IO backend like http, we need to mux stdout & stderr
// if terminal is disabled.
// But for other IO backend, it is not necessary.
// So we should make it configurable.
MuxDisabled bool
}

// NewIO creates the container's ios of stdout, stderr, stdin.
func NewIO(opt *Option) *IO {
backends := createBackend(opt)

i := &IO{
Stdout: create(opt, stdout, backends),
Stderr: create(opt, stderr, backends),
Stdout: create(opt, stdout, backends),
Stderr: create(opt, stderr, backends),
MuxDisabled: opt.muxDisabled,
}

if opt.stdin {
Expand Down
8 changes: 8 additions & 0 deletions daemon/containerio/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Option struct {
id string
rootDir string
stdin bool
muxDisabled bool
backends map[string]struct{}
hijack http.Hijacker
hijackUpgrade bool
Expand Down Expand Up @@ -54,6 +55,13 @@ func WithStdin(stdin bool) func(*Option) {
}
}

// WithMuxDisabled specified whether mux stdout & stderr of container IO.
func WithMuxDisabled(muxDisabled bool) func(*Option) {
return func(opt *Option) {
opt.muxDisabled = muxDisabled
}
}

// WithDiscard specified the discard backend.
func WithDiscard() func(*Option) {
return func(opt *Option) {
Expand Down
1 change: 1 addition & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ func (mgr *ContainerManager) openExecIO(id string, attach *AttachConfig) (*conta
options := []func(*containerio.Option){
containerio.WithID(id),
containerio.WithStdin(attach.Stdin),
containerio.WithMuxDisabled(attach.MuxDisabled),
}

if attach != nil {
Expand Down
6 changes: 6 additions & 0 deletions daemon/mgr/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ type AttachConfig struct {
Stdout bool
Stderr bool

// For IO backend like http, we need to mux stdout & stderr
// if terminal is disabled.
// But for other IO backend, it is not necessary.
// So we should make it configurable.
MuxDisabled bool

// Attach using http.
Hijack http.Hijacker
Upgrade bool
Expand Down
7 changes: 4 additions & 3 deletions daemon/mgr/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ func (c *CriManager) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (
var output bytes.Buffer
startConfig := &apitypes.ExecStartConfig{}
attachConfig := &AttachConfig{
Stdout: true,
Stderr: true,
MemBuffer: &output,
Stdout: true,
Stderr: true,
MemBuffer: &output,
MuxDisabled: true,
}

err = c.ContainerMgr.StartExec(ctx, execid, startConfig, attachConfig)
Expand Down
3 changes: 2 additions & 1 deletion daemon/mgr/cri_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (s *streamRuntime) Exec(containerID string, cmd []string, streamOpts *remot

startConfig := &apitypes.ExecStartConfig{}
attachConfig := &AttachConfig{
Streams: streams,
Streams: streams,
MuxDisabled: true,
}

err = s.containerMgr.StartExec(ctx, execid, startConfig, attachConfig)
Expand Down
2 changes: 1 addition & 1 deletion hack/cri-test/test-cri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ POUCH_SOCK="/var/run/pouchcri.sock"
CRI_FOCUS=${CRI_FOCUS:-}

# CRI_SKIP skips the test to skip.
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options|runtime should support RunAsUser|should support safe sysctls|runtime should support exec|runtime should support HostPID|runtime should support execSync|should support unsafe sysctls"}
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options"}
# REPORT_DIR is the the directory to store test logs.
REPORT_DIR=${REPORT_DIR:-"/tmp/test-cri"}

Expand Down

0 comments on commit a337da8

Please sign in to comment.