summaryrefslogtreecommitdiffhomepage
path: root/runsc/container
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2019-06-18 15:34:58 -0700
committergVisor bot <gvisor-bot@google.com>2019-06-18 15:36:17 -0700
commit0e07c94d545aa971bb2a05b738f856181a3ff463 (patch)
treef3ab1fb4288184060373a41bb79a007293394a4b /runsc/container
parentbdb19b82ef2aa1638d98da4b1c55ae7928437f55 (diff)
Kill sandbox process when 'runsc do' exits
PiperOrigin-RevId: 253882115
Diffstat (limited to 'runsc/container')
-rw-r--r--runsc/container/container.go19
-rw-r--r--runsc/container/container_test.go15
2 files changed, 24 insertions, 10 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go
index 3a358224c..bde46fb9b 100644
--- a/runsc/container/container.go
+++ b/runsc/container/container.go
@@ -262,7 +262,15 @@ type Args struct {
PIDFile string
// UserLog is the filename to send user-visible logs to. It may be empty.
+ //
+ // It only applies for the init container.
UserLog string
+
+ // Attached indicates that the sandbox lifecycle is attached with the caller.
+ // If the caller exits, the sandbox should exit too.
+ //
+ // It only applies for the init container.
+ Attached bool
}
// Create creates the container in a new Sandbox process, unless the metadata
@@ -349,6 +357,7 @@ func New(conf *boot.Config, args Args) (*Container, error) {
IOFiles: ioFiles,
MountsFile: specFile,
Cgroup: cg,
+ Attached: args.Attached,
}
sand, err := sandbox.New(conf, sandArgs)
if err != nil {
@@ -499,7 +508,7 @@ func (c *Container) Restore(spec *specs.Spec, conf *boot.Config, restoreFile str
}
// Run is a helper that calls Create + Start + Wait.
-func Run(conf *boot.Config, args Args, detach bool) (syscall.WaitStatus, error) {
+func Run(conf *boot.Config, args Args) (syscall.WaitStatus, error) {
log.Debugf("Run container %q in root dir: %s", args.ID, conf.RootDir)
c, err := New(conf, args)
if err != nil {
@@ -522,11 +531,11 @@ func Run(conf *boot.Config, args Args, detach bool) (syscall.WaitStatus, error)
return 0, fmt.Errorf("starting container: %v", err)
}
}
- if detach {
- cu.Release()
- return 0, nil
+ if args.Attached {
+ return c.Wait()
}
- return c.Wait()
+ cu.Release()
+ return 0, nil
}
// Execute runs the specified command in the container. It returns the PID of
diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go
index 610dd1bf8..e0786866b 100644
--- a/runsc/container/container_test.go
+++ b/runsc/container/container_test.go
@@ -215,8 +215,9 @@ func run(spec *specs.Spec, conf *boot.Config) error {
ID: testutil.UniqueContainerID(),
Spec: spec,
BundleDir: bundleDir,
+ Attached: true,
}
- ws, err := Run(conf, args, false)
+ ws, err := Run(conf, args)
if err != nil {
return fmt.Errorf("running container: %v", err)
}
@@ -430,8 +431,9 @@ func TestExePath(t *testing.T) {
ID: testutil.UniqueContainerID(),
Spec: spec,
BundleDir: bundleDir,
+ Attached: true,
}
- ws, err := Run(conf, args, false)
+ ws, err := Run(conf, args)
os.RemoveAll(rootDir)
os.RemoveAll(bundleDir)
@@ -468,8 +470,9 @@ func TestAppExitStatus(t *testing.T) {
ID: testutil.UniqueContainerID(),
Spec: succSpec,
BundleDir: bundleDir,
+ Attached: true,
}
- ws, err := Run(conf, args, false)
+ ws, err := Run(conf, args)
if err != nil {
t.Fatalf("error running container: %v", err)
}
@@ -492,8 +495,9 @@ func TestAppExitStatus(t *testing.T) {
ID: testutil.UniqueContainerID(),
Spec: errSpec,
BundleDir: bundleDir2,
+ Attached: true,
}
- ws, err = Run(conf, args2, false)
+ ws, err = Run(conf, args2)
if err != nil {
t.Fatalf("error running container: %v", err)
}
@@ -1624,8 +1628,9 @@ func TestUserLog(t *testing.T) {
Spec: spec,
BundleDir: bundleDir,
UserLog: userLog,
+ Attached: true,
}
- ws, err := Run(conf, args, false)
+ ws, err := Run(conf, args)
if err != nil {
t.Fatalf("error running container: %v", err)
}