Copy io into and out of console
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
07e2b63d69
commit
4f644dbfd5
@ -135,9 +135,17 @@ var Command = cli.Command{
|
|||||||
if context.Bool("rm") && !detach {
|
if context.Bool("rm") && !detach {
|
||||||
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
||||||
}
|
}
|
||||||
|
var con console.Console
|
||||||
|
if tty {
|
||||||
|
con = console.Current()
|
||||||
|
defer con.Reset()
|
||||||
|
if err := con.SetRaw(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
opts := getNewTaskOpts(context)
|
opts := getNewTaskOpts(context)
|
||||||
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
||||||
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), tty, context.Bool("null-io"), ioOpts, opts...)
|
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), con, context.Bool("null-io"), ioOpts, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -153,14 +161,6 @@ var Command = cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var con console.Console
|
|
||||||
if tty {
|
|
||||||
con = console.Current()
|
|
||||||
defer con.Reset()
|
|
||||||
if err := con.SetRaw(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,21 @@ var startCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tty = spec.Process.Terminal
|
tty = spec.Process.Terminal
|
||||||
opts = getNewTaskOpts(context)
|
opts = getNewTaskOpts(context)
|
||||||
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
||||||
)
|
)
|
||||||
task, err := NewTask(ctx, client, container, "", tty, context.Bool("null-io"), ioOpts, opts...)
|
var con console.Console
|
||||||
|
if tty {
|
||||||
|
con = console.Current()
|
||||||
|
defer con.Reset()
|
||||||
|
if err := con.SetRaw(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task, err := NewTask(ctx, client, container, "", con, context.Bool("null-io"), ioOpts, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -86,14 +94,6 @@ var startCommand = cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var con console.Console
|
|
||||||
if tty {
|
|
||||||
con = console.Current()
|
|
||||||
defer con.Reset()
|
|
||||||
if err := con.SetRaw(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// NewTask creates a new task
|
||||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||||
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
||||||
if checkpoint != "" {
|
if checkpoint != "" {
|
||||||
im, err := client.GetImage(ctx, checkpoint)
|
im, err := client.GetImage(ctx, checkpoint)
|
||||||
@ -77,11 +77,11 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
|||||||
opts = append(opts, containerd.WithTaskCheckpoint(im))
|
opts = append(opts, containerd.WithTaskCheckpoint(im))
|
||||||
}
|
}
|
||||||
ioCreator := stdio
|
ioCreator := stdio
|
||||||
if tty {
|
if con != nil {
|
||||||
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
|
||||||
}
|
}
|
||||||
if nullIO {
|
if nullIO {
|
||||||
if tty {
|
if con != nil {
|
||||||
return nil, errors.New("tty and null-io cannot be used together")
|
return nil, errors.New("tty and null-io cannot be used together")
|
||||||
}
|
}
|
||||||
ioCreator = cio.NullIO
|
ioCreator = cio.NullIO
|
||||||
|
@ -58,13 +58,13 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// NewTask creates a new task
|
||||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||||
var ioCreator cio.Creator
|
var ioCreator cio.Creator
|
||||||
if tty {
|
if con != nil {
|
||||||
if nullIO {
|
if nullIO {
|
||||||
return nil, errors.New("tty and null-io cannot be used together")
|
return nil, errors.New("tty and null-io cannot be used together")
|
||||||
}
|
}
|
||||||
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, con), cio.WithTerminal}, ioOpts...)...)
|
||||||
} else if nullIO {
|
} else if nullIO {
|
||||||
ioCreator = cio.NullIO
|
ioCreator = cio.NullIO
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user