Skip to content

Commit e695ddb

Browse files
authored
Merge pull request containerd#10499 from TinaMor/cherry-pick-of-#10412-upstream-release-1.7
[release/1.7] [Windows] Set stderr to empty string when using terminal on Windows.
2 parents 8fc6bcf + f9beac3 commit e695ddb

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
@@ -268,26 +268,6 @@ func BinaryIO(binary string, args map[string]string) Creator {
268268
}
269269
}
270270

271-
// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
272-
// It also sets the terminal option to true
273-
func TerminalBinaryIO(binary string, args map[string]string) Creator {
274-
return func(_ string) (IO, error) {
275-
uri, err := LogURIGenerator("binary", binary, args)
276-
if err != nil {
277-
return nil, err
278-
}
279-
280-
res := uri.String()
281-
return &logURI{
282-
config: Config{
283-
Stdout: res,
284-
Stderr: res,
285-
Terminal: true,
286-
},
287-
}, nil
288-
}
289-
}
290-
291271
// LogFile creates a file on disk that logs the task's STDOUT,STDERR.
292272
// If the log file already exists, the logs will be appended to the file.
293273
func LogFile(path string) Creator {

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+
}

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)