diff --git a/pkg/shim/proc/BUILD b/pkg/shim/proc/BUILD index eec851936..653596ea5 100644 --- a/pkg/shim/proc/BUILD +++ b/pkg/shim/proc/BUILD @@ -23,6 +23,7 @@ go_library( "//pkg/atomicbitops", "//pkg/cleanup", "//pkg/shim/runsc", + "//pkg/shim/utils", "@com_github_containerd_console//:go_default_library", "@com_github_containerd_containerd//errdefs:go_default_library", "@com_github_containerd_containerd//log:go_default_library", diff --git a/pkg/shim/proc/init.go b/pkg/shim/proc/init.go index d01ad61ac..fcdc8e2bc 100644 --- a/pkg/shim/proc/init.go +++ b/pkg/shim/proc/init.go @@ -38,6 +38,7 @@ import ( specs "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/shim/runsc" + "gvisor.dev/gvisor/pkg/shim/utils" ) const statusStopped = "stopped" @@ -74,12 +75,11 @@ type Init struct { IoGID int Sandbox bool UserLog string - PanicLog string Monitor ProcessMonitor } // NewRunsc returns a new runsc instance for a process. -func NewRunsc(root, path, namespace, runtime string, config map[string]string) *runsc.Runsc { +func NewRunsc(root, path, namespace, runtime string, config map[string]string, spec *specs.Spec) *runsc.Runsc { if root == "" { root = RunscRoot } @@ -88,6 +88,7 @@ func NewRunsc(root, path, namespace, runtime string, config map[string]string) * PdeathSignal: unix.SIGKILL, Log: filepath.Join(path, "log.json"), LogFormat: runc.JSON, + PanicLog: utils.PanicLogPath(spec), Root: filepath.Join(root, namespace), Config: config, } diff --git a/pkg/shim/runsc/runsc.go b/pkg/shim/runsc/runsc.go index a3404744c..459f3f8d2 100644 --- a/pkg/shim/runsc/runsc.go +++ b/pkg/shim/runsc/runsc.go @@ -69,6 +69,7 @@ type Runsc struct { Root string Log string LogFormat runc.Format + PanicLog string Config map[string]string } @@ -108,10 +109,6 @@ type CreateOpts struct { // UserLog is a path to where runsc user log should be generated. UserLog string - - // PanicLog is a path to where runsc will output its panic message - // (in case it does panic). - PanicLog string } func (o *CreateOpts) args() (out []string, err error) { @@ -128,9 +125,6 @@ func (o *CreateOpts) args() (out []string, err error) { if o.UserLog != "" { out = append(out, "--user-log", o.UserLog) } - if o.PanicLog != "" { - out = append(out, "--panic-log", o.PanicLog) - } return out, nil } @@ -493,6 +487,9 @@ func (r *Runsc) args() []string { if r.LogFormat != "" { args = append(args, fmt.Sprintf("--log-format=%s", r.LogFormat)) } + if r.PanicLog != "" { + args = append(args, fmt.Sprintf("--panic-log=%s", r.PanicLog)) + } for k, v := range r.Config { args = append(args, fmt.Sprintf("--%s=%s", k, v)) } diff --git a/pkg/shim/service.go b/pkg/shim/service.go index 35d969d3a..a6904e1ae 100644 --- a/pkg/shim/service.go +++ b/pkg/shim/service.go @@ -304,7 +304,7 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error) if err := st.load(path); err != nil { return nil, err } - r := proc.NewRunsc(s.opts.Root, path, ns, st.Options.BinaryName, nil) + r := proc.NewRunsc(s.opts.Root, path, ns, st.Options.BinaryName, nil, nil) if err := r.Delete(ctx, s.id, &runsc.DeleteOpts{ Force: true, @@ -1082,7 +1082,7 @@ func newInit(path, workDir, namespace string, platform stdio.Platform, r *proc.C } runsc.FormatRunscPaths(r.ID, options.RunscConfig) - runtime := proc.NewRunsc(options.Root, path, namespace, options.BinaryName, options.RunscConfig) + runtime := proc.NewRunsc(options.Root, path, namespace, options.BinaryName, options.RunscConfig, spec) p := proc.New(r.ID, runtime, stdio.Stdio{ Stdin: r.Stdin, Stdout: r.Stdout, @@ -1097,7 +1097,6 @@ func newInit(path, workDir, namespace string, platform stdio.Platform, r *proc.C p.IoGID = int(options.IoGID) p.Sandbox = specutils.SpecContainerType(spec) == specutils.ContainerTypeSandbox p.UserLog = utils.UserLogPath(spec) - p.PanicLog = utils.PanicLogPath(spec) p.Monitor = reaper.Default return p, nil } diff --git a/pkg/shim/utils/utils.go b/pkg/shim/utils/utils.go index 10c7340e3..8ccc4a706 100644 --- a/pkg/shim/utils/utils.go +++ b/pkg/shim/utils/utils.go @@ -64,6 +64,9 @@ func UserLogPath(spec *specs.Spec) string { // PanicLogPath gets the panic log path from OCI annotation. func PanicLogPath(spec *specs.Spec) string { + if spec == nil { + return "" + } sandboxLogDir := spec.Annotations[sandboxLogDirAnnotation] if sandboxLogDir == "" { return ""