Skip to content

Commit eaa1afe

Browse files
committed
Set stderr to empty string when using terminal on Windows.
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]>
1 parent cbb2fc7 commit eaa1afe

3 files changed

Lines changed: 75 additions & 34 deletions

File tree

pkg/cio/io.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,6 @@ func LogURI(uri *url.URL) Creator {
252252
}
253253
}
254254

255-
// TerminalLogURI provides the raw logging URI
256-
// as well as sets the terminal option to true.
257-
func TerminalLogURI(uri *url.URL) Creator {
258-
return func(_ string) (IO, error) {
259-
return &logURI{
260-
config: Config{
261-
Stdout: uri.String(),
262-
Stderr: uri.String(),
263-
Terminal: true,
264-
},
265-
}, nil
266-
}
267-
}
268-
269255
// BinaryIO forwards container STDOUT|STDERR directly to a logging binary
270256
func BinaryIO(binary string, args map[string]string) Creator {
271257
return func(_ string) (IO, error) {
@@ -284,26 +270,6 @@ func BinaryIO(binary string, args map[string]string) Creator {
284270
}
285271
}
286272

287-
// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
288-
// It also sets the terminal option to true
289-
func TerminalBinaryIO(binary string, args map[string]string) Creator {
290-
return func(_ string) (IO, error) {
291-
uri, err := LogURIGenerator("binary", binary, args)
292-
if err != nil {
293-
return nil, err
294-
}
295-
296-
res := uri.String()
297-
return &logURI{
298-
config: Config{
299-
Stdout: res,
300-
Stderr: res,
301-
Terminal: true,
302-
},
303-
}, nil
304-
}
305-
}
306-
307273
// LogFile creates a file on disk that logs the task's STDOUT,STDERR.
308274
// If the log file already exists, the logs will be appended to the file.
309275
func LogFile(path string) Creator {

pkg/cio/io_unix.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323
"fmt"
2424
"io"
25+
"net/url"
2526
"os"
2627
"path/filepath"
2728
"sync"
@@ -158,3 +159,37 @@ func NewDirectIO(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) {
158159
},
159160
}, err
160161
}
162+
163+
// TerminalLogURI provides the raw logging URI
164+
// as well as sets the terminal option to true.
165+
func TerminalLogURI(uri *url.URL) Creator {
166+
return func(_ string) (IO, error) {
167+
return &logURI{
168+
config: Config{
169+
Stdout: uri.String(),
170+
Stderr: uri.String(),
171+
Terminal: true,
172+
},
173+
}, nil
174+
}
175+
}
176+
177+
// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
178+
// It also sets the terminal option to true
179+
func TerminalBinaryIO(binary string, args map[string]string) Creator {
180+
return func(_ string) (IO, error) {
181+
uri, err := LogURIGenerator("binary", binary, args)
182+
if err != nil {
183+
return nil, err
184+
}
185+
186+
res := uri.String()
187+
return &logURI{
188+
config: Config{
189+
Stdout: res,
190+
Stderr: res,
191+
Terminal: true,
192+
},
193+
}, nil
194+
}
195+
}

pkg/cio/io_windows.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23+
"net/url"
2324

2425
winio "github.com/Microsoft/go-winio"
2526
"github.com/containerd/log"
@@ -155,3 +156,42 @@ func NewDirectIOFromFIFOSet(ctx context.Context, stdin io.WriteCloser, stdout, s
155156
},
156157
}
157158
}
159+
160+
// TerminalLogURI provides the raw logging URI
161+
// as well as sets the terminal option to true.
162+
func TerminalLogURI(uri *url.URL) Creator {
163+
return func(_ string) (IO, error) {
164+
return &logURI{
165+
config: Config{
166+
Terminal: true,
167+
Stdout: uri.String(),
168+
169+
// Windows HCSShim requires that stderr is an empty string when using terminal.
170+
// https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127
171+
Stderr: "",
172+
},
173+
}, nil
174+
}
175+
}
176+
177+
// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
178+
// It also sets the terminal option to true
179+
func TerminalBinaryIO(binary string, args map[string]string) Creator {
180+
return func(_ string) (IO, error) {
181+
uri, err := LogURIGenerator("binary", binary, args)
182+
if err != nil {
183+
return nil, err
184+
}
185+
186+
return &logURI{
187+
config: Config{
188+
Terminal: true,
189+
Stdout: uri.String(),
190+
191+
// Windows HCSShim requires that stderr is an empty string when using terminal.
192+
// https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127
193+
Stderr: "",
194+
},
195+
}, nil
196+
}
197+
}

0 commit comments

Comments
 (0)