mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Initial commit of runc binary
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
)
|
||||
|
||||
func execContainer(context *cli.Context, spec *LinuxSpec) (int, error) {
|
||||
if len(spec.Processes) != 1 {
|
||||
return -1, fmt.Errorf("runc only supports one(1) process for the container")
|
||||
}
|
||||
config, err := createLibcontainerConfig(spec)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
rootuid, err := config.HostUID()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
factory, err := loadFactory(context)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
container, err := factory.Create(context.GlobalString("id"), config)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
// ensure that the container is always removed if we were the process
|
||||
// that created it.
|
||||
defer destroy(container)
|
||||
process := newProcess(spec.Processes[0])
|
||||
tty, err := newTty(spec.Processes[0].TTY, process, rootuid)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
handler := newSignalHandler(tty)
|
||||
defer handler.Close()
|
||||
if err := container.Start(process); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return handler.forward(process)
|
||||
}
|
||||
|
||||
func destroy(container libcontainer.Container) {
|
||||
status, err := container.Status()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if status != libcontainer.Checkpointed {
|
||||
if err := container.Destroy(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user