Skip to content

Commit 4c4c9b8

Browse files
committed
Add --console to specify path to use from runc
This flag allows systems that are running runc to allocate tty's that they own and provide to the container. Signed-off-by: Michael Crosby <[email protected]>
1 parent 5c46b9d commit 4c4c9b8

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

exec.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515
var execCommand = cli.Command{
1616
Name: "exec",
1717
Usage: "execute new process inside the container",
18+
Flags: []cli.Flag{
19+
cli.StringFlag{
20+
Name: "console",
21+
Value: "",
22+
Usage: "specify the pty slave path for use with the container",
23+
},
24+
},
1825
Action: func(context *cli.Context) {
1926
config, err := loadProcessConfig(context.Args().First())
2027
if err != nil {
@@ -45,7 +52,7 @@ func execProcess(context *cli.Context, config *specs.Process) (int, error) {
4552
if err != nil {
4653
return -1, err
4754
}
48-
tty, err := newTty(config.Terminal, process, rootuid)
55+
tty, err := newTty(config.Terminal, process, rootuid, context.String("console"))
4956
if err != nil {
5057
return -1, err
5158
}

restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi
114114
Stdout: os.Stdout,
115115
Stderr: os.Stderr,
116116
}
117-
tty, err := newTty(spec.Process.Terminal, process, rootuid)
117+
tty, err := newTty(spec.Process.Terminal, process, rootuid, "")
118118
if err != nil {
119119
return -1, err
120120
}

start.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ var startCommand = cli.Command{
2626
Value: "",
2727
Usage: "path to the root of the bundle directory",
2828
},
29+
cli.StringFlag{
30+
Name: "console",
31+
Value: "",
32+
Usage: "specify the pty slave path for use with the container",
33+
},
2934
},
3035
Action: func(context *cli.Context) {
3136
bundle := context.String("bundle")
@@ -44,9 +49,10 @@ var startCommand = cli.Command{
4449
setupSdNotify(spec, rspec, notifySocket)
4550
}
4651

47-
listenFds := os.Getenv("LISTEN_FDS")
48-
listenPid := os.Getenv("LISTEN_PID")
49-
52+
var (
53+
listenFds = os.Getenv("LISTEN_FDS")
54+
listenPid = os.Getenv("LISTEN_PID")
55+
)
5056
if listenFds != "" && listenPid == strconv.Itoa(os.Getpid()) {
5157
setupSocketActivation(spec, listenFds)
5258
}
@@ -114,7 +120,7 @@ func startContainer(context *cli.Context, spec *specs.LinuxSpec, rspec *specs.Li
114120
process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), ""))
115121
}
116122
}
117-
tty, err := newTty(spec.Process.Terminal, process, rootuid)
123+
tty, err := newTty(spec.Process.Terminal, process, rootuid, context.String("console"))
118124
if err != nil {
119125
return -1, err
120126
}

tty.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
// newTty creates a new tty for use with the container. If a tty is not to be
1515
// created for the process, pipes are created so that the TTY of the parent
1616
// process are not inherited by the container.
17-
func newTty(create bool, p *libcontainer.Process, rootuid int) (*tty, error) {
17+
func newTty(create bool, p *libcontainer.Process, rootuid int, console string) (*tty, error) {
1818
if create {
19-
return createTty(p, rootuid)
19+
return createTty(p, rootuid, console)
2020
}
2121
return createStdioPipes(p, rootuid)
2222
}
@@ -41,13 +41,20 @@ func createStdioPipes(p *libcontainer.Process, rootuid int) (*tty, error) {
4141
return t, nil
4242
}
4343

44-
func createTty(p *libcontainer.Process, rootuid int) (*tty, error) {
44+
func createTty(p *libcontainer.Process, rootuid int, consolePath string) (*tty, error) {
45+
if consolePath != "" {
46+
if err := p.ConsoleFromPath(consolePath); err != nil {
47+
return nil, err
48+
}
49+
return &tty{}, nil
50+
}
4551
console, err := p.NewConsole(rootuid)
4652
if err != nil {
4753
return nil, err
4854
}
4955
go io.Copy(console, os.Stdin)
5056
go io.Copy(os.Stdout, console)
57+
5158
state, err := term.SetRawTerminal(os.Stdin.Fd())
5259
if err != nil {
5360
return nil, fmt.Errorf("failed to set the terminal from the stdin: %v", err)

0 commit comments

Comments
 (0)