Skip to content

Commit a776109

Browse files
committed
Fix console size bug
Currently the uvmboot code doesn't set a size for the console, that causes it to use the default size and causes weird formatting errors. This fixes that by explicitly passing the current window/console's size. Signed-off-by: Amit Barve <[email protected]>
1 parent 0366cb2 commit a776109

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

internal/tools/uvmboot/conf_wcow.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ package main
44

55
import (
66
"context"
7+
"fmt"
78
"os"
89

910
"github.com/containerd/console"
11+
"github.com/opencontainers/runtime-spec/specs-go"
1012
"github.com/urfave/cli"
1113

1214
"github.com/Microsoft/hcsshim/internal/cmd"
@@ -140,6 +142,14 @@ var cwcowCommand = cli.Command{
140142
cmd.Stdout = os.Stdout
141143
con, err := console.ConsoleFromFile(os.Stdin)
142144
if err == nil {
145+
csz, err := con.Size()
146+
if err != nil {
147+
return fmt.Errorf("failed to get console size: %w", err)
148+
}
149+
cmd.Spec.ConsoleSize = &specs.Box{
150+
Height: uint(csz.Height),
151+
Width: uint(csz.Width),
152+
}
143153
err = con.SetRaw()
144154
if err != nil {
145155
return err

internal/tools/uvmboot/lcow.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ package main
44

55
import (
66
"context"
7+
"fmt"
78
"io"
89
"os"
910
"strings"
1011

1112
"github.com/containerd/console"
13+
"github.com/opencontainers/runtime-spec/specs-go"
1214
"github.com/urfave/cli"
1315

1416
"github.com/Microsoft/hcsshim/internal/cmd"
@@ -306,6 +308,14 @@ func execViaGCS(ctx context.Context, vm *uvm.UtilityVM, cCtx *cli.Context) error
306308
if err != nil {
307309
log.G(ctx).WithError(err).Warn("could not create console from stdin")
308310
} else {
311+
csz, err := con.Size()
312+
if err != nil {
313+
return fmt.Errorf("failed to get console size: %w", err)
314+
}
315+
c.Spec.ConsoleSize = &specs.Box{
316+
Height: uint(csz.Height),
317+
Width: uint(csz.Width),
318+
}
309319
if err := con.SetRaw(); err != nil {
310320
return err
311321
}

internal/tools/uvmboot/wcow.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/containerd/console"
15+
"github.com/opencontainers/runtime-spec/specs-go"
1516
"github.com/urfave/cli"
1617

1718
"github.com/Microsoft/hcsshim/internal/cmd"
@@ -101,6 +102,14 @@ var wcowCommand = cli.Command{
101102
cmd.Stdout = os.Stdout
102103
con, err := console.ConsoleFromFile(os.Stdin)
103104
if err == nil {
105+
csz, err := con.Size()
106+
if err != nil {
107+
return fmt.Errorf("failed to get console size: %w", err)
108+
}
109+
cmd.Spec.ConsoleSize = &specs.Box{
110+
Height: uint(csz.Height),
111+
Width: uint(csz.Width),
112+
}
104113
err = con.SetRaw()
105114
if err != nil {
106115
return err

0 commit comments

Comments
 (0)