From 0e07c94d545aa971bb2a05b738f856181a3ff463 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Tue, 18 Jun 2019 15:34:58 -0700 Subject: Kill sandbox process when 'runsc do' exits PiperOrigin-RevId: 253882115 --- runsc/sandbox/sandbox.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'runsc/sandbox/sandbox.go') diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index bf17f62d9..00b0bf659 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -103,6 +103,10 @@ type Args struct { // Gcgroup is the cgroup that the sandbox is part of. Cgroup *cgroup.Cgroup + + // Attached indicates that the sandbox lifecycle is attached with the caller. + // If the caller exits, the sandbox should exit too. + Attached bool } // New creates the sandbox process. The caller must call Destroy() on the @@ -650,6 +654,11 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF log.Debugf("Donating FD %d: %q", i+3, f.Name()) } + if args.Attached { + // Kill sandbox if parent process exits in attached mode. + cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL + } + log.Debugf("Starting sandbox: %s %v", binPath, cmd.Args) log.Debugf("SysProcAttr: %+v", cmd.SysProcAttr) if err := specutils.StartInNS(cmd, nss); err != nil { -- cgit v1.2.3