summaryrefslogtreecommitdiffhomepage
path: root/runsc/boot
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2018-09-12 15:22:24 -0700
committerShentubot <shentubot@google.com>2018-09-12 15:23:35 -0700
commit2eff1fdd061be9cfabc36532dda8cbefeb02e534 (patch)
tree009e2a9cbca191a2d2a471b30380888cd50c0b4a /runsc/boot
parent0efde2bfbde2fea78134a32f5fb34332ec0ce531 (diff)
runsc: Add exec flag that specifies where to save the sandbox-internal pid.
This is different from the existing -pid-file flag, which saves a host pid. PiperOrigin-RevId: 212713968 Change-Id: I2c486de8dd5cfd9b923fb0970165ef7c5fc597f0
Diffstat (limited to 'runsc/boot')
-rw-r--r--runsc/boot/controller.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go
index 257f275f9..aaac852e0 100644
--- a/runsc/boot/controller.go
+++ b/runsc/boot/controller.go
@@ -41,9 +41,9 @@ const (
// container used by "runsc events".
ContainerEvent = "containerManager.Event"
- // ContainerExecute is the URPC endpoint for executing a command in a
+ // ContainerExecuteAsync is the URPC endpoint for executing a command in a
// container..
- ContainerExecute = "containerManager.Execute"
+ ContainerExecuteAsync = "containerManager.ExecuteAsync"
// ContainerPause pauses the container.
ContainerPause = "containerManager.Pause"
@@ -233,33 +233,40 @@ type ExecArgs struct {
CID string
}
-// Execute runs a command on a created or running sandbox.
-func (cm *containerManager) Execute(e *ExecArgs, waitStatus *uint32) error {
- log.Debugf("containerManager.Execute: %+v", *e)
+// ExecuteAsync starts running a command on a created or running sandbox. It
+// returns the pid of the new process.
+func (cm *containerManager) ExecuteAsync(args *ExecArgs, pid *int32) error {
+ log.Debugf("containerManager.ExecuteAsync: %+v", args)
// Get the container Root Dirent from the Task, since we must run this
// process with the same Root.
cm.l.mu.Lock()
- tgid, ok := cm.l.containerRootTGIDs[e.CID]
+ tgid, ok := cm.l.containerRootTGIDs[args.CID]
cm.l.mu.Unlock()
if !ok {
- return fmt.Errorf("cannot exec in container %q: no such container", e.CID)
+ return fmt.Errorf("cannot exec in container %q: no such container", args.CID)
}
t := cm.l.k.TaskSet().Root.TaskWithID(kernel.ThreadID(tgid))
if t == nil {
- return fmt.Errorf("cannot exec in container %q: no thread group with ID %d", e.CID, tgid)
+ return fmt.Errorf("cannot exec in container %q: no thread group with ID %d", args.CID, tgid)
}
t.WithMuLocked(func(t *kernel.Task) {
- e.Root = t.FSContext().RootDirectory()
+ args.Root = t.FSContext().RootDirectory()
})
- if e.Root != nil {
- defer e.Root.DecRef()
+ if args.Root != nil {
+ defer args.Root.DecRef()
}
+ // Start the process.
proc := control.Proc{Kernel: cm.l.k}
- if err := proc.Exec(&e.ExecArgs, waitStatus); err != nil {
- return fmt.Errorf("error executing: %+v: %v", e, err)
+ newTG, err := control.ExecAsync(&proc, &args.ExecArgs)
+ if err != nil {
+ return fmt.Errorf("error executing: %+v: %v", args, err)
}
+
+ // Return the pid of the newly-created process.
+ ts := cm.l.k.TaskSet()
+ *pid = int32(ts.Root.IDOfThreadGroup(newTG))
return nil
}