Skip to content

Commit d157b85

Browse files
authored
Merge pull request containerd#10500 from TinaMor/cherry-pick-of-#10412-upstream-release-1.6
[release/1.6] [Windows] Set stderr to empty string when using terminal on Windows
2 parents e9e2c77 + 484705c commit d157b85

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

cio/io.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,6 @@ func BinaryIO(binary string, args map[string]string) Creator {
260260
}
261261
}
262262

263-
// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
264-
// It also sets the terminal option to true
265-
func TerminalBinaryIO(binary string, args map[string]string) Creator {
266-
return func(_ string) (IO, error) {
267-
uri, err := LogURIGenerator("binary", binary, args)
268-
if err != nil {
269-
return nil, err
270-
}
271-
272-
res := uri.String()
273-
return &logURI{
274-
config: Config{
275-
Stdout: res,
276-
Stderr: res,
277-
Terminal: true,
278-
},
279-
}, nil
280-
}
281-
}
282-
283263
// LogFile creates a file on disk that logs the task's STDOUT,STDERR.
284264
// If the log file already exists, the logs will be appended to the file.
285265
func LogFile(path string) Creator {

cio/io_unix.go

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

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)