From f49e0c19ede56b1cc6b1d44ea9ba8b336cd22658 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 16 Apr 2019 14:12:12 +0200 Subject: runtime: pass down the context Signed-off-by: Giuseppe Scrivano --- libpod/options.go | 14 ++++++++++++++ libpod/runtime.go | 3 +++ libpod/runtime_migrate.go | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'libpod') diff --git a/libpod/options.go b/libpod/options.go index 949894dcb..9932d5453 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1,6 +1,7 @@ package libpod import ( + "context" "net" "os" "path/filepath" @@ -466,6 +467,19 @@ func WithShmDir(dir string) CtrCreateOption { } } +// WithContext sets the context to use. +func WithContext(ctx context.Context) RuntimeOption { + return func(rt *Runtime) error { + if rt.valid { + return ErrRuntimeFinalized + } + + rt.ctx = ctx + + return nil + } +} + // WithSystemd turns on systemd mode in the container func WithSystemd() CtrCreateOption { return func(ctr *Container) error { diff --git a/libpod/runtime.go b/libpod/runtime.go index 6d279a107..e85242028 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -1,6 +1,7 @@ package libpod import ( + "context" "fmt" "io/ioutil" "os" @@ -111,6 +112,8 @@ type Runtime struct { // mechanism to read and write even logs eventer events.Eventer + + ctx context.Context } // OCIRuntimePath contains information about an OCI runtime. diff --git a/libpod/runtime_migrate.go b/libpod/runtime_migrate.go index 7d7fa108d..a084df289 100644 --- a/libpod/runtime_migrate.go +++ b/libpod/runtime_migrate.go @@ -1,7 +1,6 @@ package libpod import ( - "context" "path/filepath" "github.com/pkg/errors" @@ -39,7 +38,7 @@ func (r *Runtime) migrate() error { } for _, ctr := range runningContainers { - if err := ctr.Start(context.Background(), true); err != nil { + if err := ctr.Start(r.ctx, true); err != nil { logrus.Errorf("error restarting container %s", ctr.ID()) } } -- cgit v1.2.3-54-g00ecf