Skip to content

Commit

Permalink
Set stderr to empty string when using terminal on Windows.
Browse files Browse the repository at this point in the history
    Windows HCSShim requires that stderr is an empty string when using terminal.
	Reference: https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127

Signed-off-by: Christine Murimi <[email protected]>
(cherry picked from commit eaa1afe)
  • Loading branch information
TinaMor committed Jul 24, 2024
1 parent e9e2c77 commit 484705c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
20 changes: 0 additions & 20 deletions cio/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,6 @@ func BinaryIO(binary string, args map[string]string) Creator {
}
}

// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
// It also sets the terminal option to true
func TerminalBinaryIO(binary string, args map[string]string) Creator {
return func(_ string) (IO, error) {
uri, err := LogURIGenerator("binary", binary, args)
if err != nil {
return nil, err
}

res := uri.String()
return &logURI{
config: Config{
Stdout: res,
Stderr: res,
Terminal: true,
},
}, nil
}
}

// LogFile creates a file on disk that logs the task's STDOUT,STDERR.
// If the log file already exists, the logs will be appended to the file.
func LogFile(path string) Creator {
Expand Down
35 changes: 35 additions & 0 deletions cio/io_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"fmt"
"io"
"net/url"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -152,3 +153,37 @@ func NewDirectIO(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) {
},
}, err
}

// TerminalLogURI provides the raw logging URI
// as well as sets the terminal option to true.
func TerminalLogURI(uri *url.URL) Creator {
return func(_ string) (IO, error) {
return &logURI{
config: Config{
Stdout: uri.String(),
Stderr: uri.String(),
Terminal: true,
},
}, nil
}
}

// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
// It also sets the terminal option to true
func TerminalBinaryIO(binary string, args map[string]string) Creator {
return func(_ string) (IO, error) {
uri, err := LogURIGenerator("binary", binary, args)
if err != nil {
return nil, err
}

res := uri.String()
return &logURI{
config: Config{
Stdout: res,
Stderr: res,
Terminal: true,
},
}, nil
}
}
40 changes: 40 additions & 0 deletions cio/io_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"net/url"

winio "github.com/Microsoft/go-winio"
"github.com/containerd/log"
Expand Down Expand Up @@ -155,3 +156,42 @@ func NewDirectIOFromFIFOSet(ctx context.Context, stdin io.WriteCloser, stdout, s
},
}
}

// TerminalLogURI provides the raw logging URI
// as well as sets the terminal option to true.
func TerminalLogURI(uri *url.URL) Creator {
return func(_ string) (IO, error) {
return &logURI{
config: Config{
Terminal: true,
Stdout: uri.String(),

// Windows HCSShim requires that stderr is an empty string when using terminal.
// https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127
Stderr: "",
},
}, nil
}
}

// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
// It also sets the terminal option to true
func TerminalBinaryIO(binary string, args map[string]string) Creator {
return func(_ string) (IO, error) {
uri, err := LogURIGenerator("binary", binary, args)
if err != nil {
return nil, err
}

return &logURI{
config: Config{
Terminal: true,
Stdout: uri.String(),

// Windows HCSShim requires that stderr is an empty string when using terminal.
// https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127
Stderr: "",
},
}, nil
}
}

0 comments on commit 484705c

Please sign in to comment.