Pass through panic-log flag to the base runsc cmd, not a subcommand.

Previously this flag was attempted to be passed into the Create subcommand,
which would not accept the flag.

PiperOrigin-RevId: 513028383
This commit is contained in:
Konstantin Bogomolov
2023-02-28 13:48:29 -08:00
committed by gVisor bot
parent 802c800ebc
commit eb98adf08c
5 changed files with 13 additions and 12 deletions
+1
View File
@@ -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",
+3 -2
View File
@@ -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,
}
+4 -7
View File
@@ -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))
}
+2 -3
View File
@@ -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
}
+3
View File
@@ -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 ""