...
1
2
3 package main
4
5 import (
6 gcontext "context"
7 "fmt"
8 "strconv"
9
10 "github.com/Microsoft/hcsshim/internal/appargs"
11 "github.com/urfave/cli"
12 )
13
14 var resizeTtyCommand = cli.Command{
15 Name: "resize-tty",
16 Usage: "resize-tty updates the terminal size for a container process",
17 ArgsUsage: `<container-id> <width> <height>`,
18 Flags: []cli.Flag{
19 &cli.IntFlag{
20 Name: "pid, p",
21 Usage: "the process pid (defaults to init pid)",
22 },
23 },
24 Before: appargs.Validate(
25 argID,
26 appargs.Int(10, 1, 65535),
27 appargs.Int(10, 1, 65535),
28 ),
29 Action: func(context *cli.Context) error {
30 id := context.Args()[0]
31 width, _ := strconv.ParseUint(context.Args()[1], 10, 16)
32 height, _ := strconv.ParseUint(context.Args()[2], 10, 16)
33 c, err := getContainer(id, true)
34 if err != nil {
35 return err
36 }
37 defer c.Close()
38
39 pid := context.Int("pid")
40 if pid == 0 {
41 if err := stateKey.Get(id, keyInitPid, &pid); err != nil {
42 return err
43 }
44 } else {
45
46 if err := stateKey.Get(id, fmt.Sprintf(keyPidMapFmt, pid), &pid); err != nil {
47 return err
48 }
49 }
50
51 p, err := c.hc.OpenProcess(gcontext.Background(), pid)
52 if err != nil {
53 return err
54 }
55 defer p.Close()
56
57 return p.ResizeConsole(gcontext.Background(), uint16(width), uint16(height))
58 },
59 }
60
View as plain text