From 41308ffa5722d4b6868ed2214de5005fb6e1dab6 Mon Sep 17 00:00:00 2001 From: yuexiao-wang Date: Fri, 5 May 2017 01:32:43 +0800 Subject: [PATCH] optimize for shimCreateCommand Signed-off-by: yuexiao-wang --- cmd/ctr/shim.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/ctr/shim.go b/cmd/ctr/shim.go index 44165b8d7..5bd4442a6 100644 --- a/cmd/ctr/shim.go +++ b/cmd/ctr/shim.go @@ -78,7 +78,11 @@ var shimCreateCommand = cli.Command{ }, ), Action: func(context *cli.Context) error { - id := context.Args().First() + var ( + id = context.Args().First() + ctx = gocontext.Background() + ) + if id == "" { return errors.New("container id must be provided") } @@ -91,7 +95,7 @@ var shimCreateCommand = cli.Command{ if err != nil { return err } - r, err := service.Create(gocontext.Background(), &shim.CreateRequest{ + r, err := service.Create(ctx, &shim.CreateRequest{ ID: id, Bundle: context.String("bundle"), Runtime: context.String("runtime"), @@ -115,7 +119,7 @@ var shimCreateCommand = cli.Command{ if err != nil { return err } - if _, err := service.Pty(gocontext.Background(), &shim.PtyRequest{ + if _, err := service.Pty(ctx, &shim.PtyRequest{ Pid: r.Pid, Width: uint32(size.Width), Height: uint32(size.Height), @@ -210,6 +214,7 @@ var shimExecCommand = cli.Command{ ), Action: func(context *cli.Context) error { service, err := getShimService() + ctx := gocontext.Background() if err != nil { return err } @@ -235,7 +240,7 @@ var shimExecCommand = cli.Command{ Stderr: context.String("stderr"), Terminal: tty, } - r, err := service.Exec(gocontext.Background(), rq) + r, err := service.Exec(ctx, rq) if err != nil { return err } @@ -252,7 +257,7 @@ var shimExecCommand = cli.Command{ if err != nil { return err } - if _, err := service.Pty(gocontext.Background(), &shim.PtyRequest{ + if _, err := service.Pty(ctx, &shim.PtyRequest{ Pid: r.Pid, Width: uint32(size.Width), Height: uint32(size.Height),