2016-10-04 17:45:09 +00:00
|
|
|
|
package shim
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2016-10-05 22:07:20 +00:00
|
|
|
|
"errors"
|
2016-10-04 17:45:09 +00:00
|
|
|
|
"fmt"
|
2016-10-06 18:39:12 +00:00
|
|
|
|
"io/ioutil"
|
2016-10-04 17:45:09 +00:00
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"sync"
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
"github.com/docker/containerd"
|
2016-12-02 23:37:16 +00:00
|
|
|
|
"github.com/docker/containerd/executors/oci"
|
2016-12-01 18:47:47 +00:00
|
|
|
|
"github.com/docker/containerd/monitor"
|
2016-10-05 22:07:20 +00:00
|
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
2016-10-04 17:45:09 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
├── libcontainerd
|
|
|
|
|
│ ├── containerd
|
|
|
|
|
│ │ └── ff2e86955c2be43f0e3c300fbd3786599301bd8efcaa5a386587f132e73af242
|
|
|
|
|
│ │ ├── init
|
|
|
|
|
│ │ │ ├── control
|
|
|
|
|
│ │ │ ├── exit
|
|
|
|
|
│ │ │ ├── log.json
|
|
|
|
|
│ │ │ ├── pid
|
|
|
|
|
│ │ │ ├── process.json
|
|
|
|
|
│ │ │ ├── shim-log.json
|
|
|
|
|
│ │ │ └── starttime
|
|
|
|
|
│ │ └── state.json
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-05 22:07:20 +00:00
|
|
|
|
var (
|
|
|
|
|
ErrNotFifo = errors.New("shim: IO is not a valid fifo on disk")
|
|
|
|
|
errInitProcessNotExist = errors.New("shim: init process does not exist")
|
|
|
|
|
)
|
2016-10-04 17:45:09 +00:00
|
|
|
|
|
2016-10-05 22:07:20 +00:00
|
|
|
|
type Opts struct {
|
|
|
|
|
Name string
|
|
|
|
|
RuntimeName string
|
|
|
|
|
RuntimeArgs []string
|
2016-10-06 18:39:12 +00:00
|
|
|
|
RuntimeRoot string
|
2016-10-05 22:07:20 +00:00
|
|
|
|
NoPivotRoot bool
|
|
|
|
|
Root string
|
|
|
|
|
Timeout time.Duration
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New(opts Opts) (*Shim, error) {
|
2016-10-06 18:39:12 +00:00
|
|
|
|
if err := os.MkdirAll(filepath.Dir(opts.Root), 0711); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
if err := os.Mkdir(opts.Root, 0711); err != nil {
|
2016-10-04 17:45:09 +00:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
r, err := oci.New(oci.Opts{
|
2016-10-06 18:39:12 +00:00
|
|
|
|
Root: opts.RuntimeRoot,
|
2016-10-05 22:07:20 +00:00
|
|
|
|
Name: opts.RuntimeName,
|
|
|
|
|
Args: opts.RuntimeArgs,
|
2016-10-04 17:45:09 +00:00
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-06 18:46:03 +00:00
|
|
|
|
m, err := monitor.New()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
s := &Shim{
|
|
|
|
|
root: opts.Root,
|
|
|
|
|
name: opts.Name,
|
|
|
|
|
timeout: opts.Timeout,
|
|
|
|
|
runtime: r,
|
|
|
|
|
processes: make(map[string]*process),
|
2016-10-06 18:46:03 +00:00
|
|
|
|
m: m,
|
2016-10-05 22:07:20 +00:00
|
|
|
|
}
|
2016-10-06 18:46:03 +00:00
|
|
|
|
go s.startMonitor()
|
2016-10-05 22:07:20 +00:00
|
|
|
|
f, err := os.Create(filepath.Join(opts.Root, "state.json"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
err = json.NewEncoder(f).Encode(s)
|
|
|
|
|
f.Close()
|
|
|
|
|
return s, err
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load will load an existing shim with all its information restored from the
|
|
|
|
|
// provided path
|
2016-10-05 22:07:20 +00:00
|
|
|
|
func Load(root string) (*Shim, error) {
|
|
|
|
|
f, err := os.Open(filepath.Join(root, "state.json"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
var s Shim
|
|
|
|
|
err = json.NewDecoder(f).Decode(&s)
|
|
|
|
|
f.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-06 18:54:59 +00:00
|
|
|
|
m, err := monitor.New()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
s.m = m
|
2016-10-06 22:06:34 +00:00
|
|
|
|
go s.startMonitor()
|
2016-10-06 18:39:12 +00:00
|
|
|
|
dirs, err := ioutil.ReadDir(root)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, d := range dirs {
|
|
|
|
|
if !d.IsDir() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
name := d.Name()
|
|
|
|
|
if f, err = os.Open(filepath.Join(root, name, "process.json")); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
var p process
|
|
|
|
|
err = json.NewDecoder(f).Decode(&p)
|
|
|
|
|
f.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
s.processes[name] = &p
|
2016-10-06 18:54:59 +00:00
|
|
|
|
if err := s.m.Add(&p); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-06 18:39:12 +00:00
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
return &s, nil
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Shim is a container runtime that adds a shim process as the container's parent
|
|
|
|
|
// to hold open stdio and other resources so that higher level daemons can exit and
|
|
|
|
|
// load running containers for handling upgrades and/or crashes
|
|
|
|
|
//
|
|
|
|
|
// The shim uses an OCI compliant runtime as its executor
|
|
|
|
|
type Shim struct {
|
|
|
|
|
// root holds runtime state information for the containers
|
|
|
|
|
// launched by the runtime
|
2016-10-05 22:07:20 +00:00
|
|
|
|
root string
|
|
|
|
|
name string
|
|
|
|
|
timeout time.Duration
|
|
|
|
|
noPivotRoot bool
|
|
|
|
|
runtime *oci.OCIRuntime
|
|
|
|
|
pmu sync.Mutex
|
|
|
|
|
processes map[string]*process
|
|
|
|
|
bundle string
|
|
|
|
|
checkpoint string
|
2016-10-06 18:46:03 +00:00
|
|
|
|
m *monitor.Monitor
|
2016-10-05 22:07:20 +00:00
|
|
|
|
}
|
2016-10-04 17:45:09 +00:00
|
|
|
|
|
2016-10-05 22:07:20 +00:00
|
|
|
|
type state struct {
|
2016-10-06 22:18:26 +00:00
|
|
|
|
Root string `json:"root"`
|
2016-10-05 22:07:20 +00:00
|
|
|
|
// Bundle is the path to the container's bundle
|
|
|
|
|
Bundle string `json:"bundle"`
|
|
|
|
|
// OCI runtime binary name
|
|
|
|
|
Runtime string `json:"runtime"`
|
|
|
|
|
// OCI runtime args
|
|
|
|
|
RuntimeArgs []string `json:"runtimeArgs"`
|
2016-10-06 22:18:26 +00:00
|
|
|
|
RuntimeRoot string `json:"runtimeRoot"`
|
2016-10-05 22:07:20 +00:00
|
|
|
|
// Shim binary name
|
|
|
|
|
Name string `json:"shim"`
|
|
|
|
|
/// NoPivotRoot option
|
|
|
|
|
NoPivotRoot bool `json:"noPivotRoot"`
|
|
|
|
|
// Timeout for container start
|
|
|
|
|
Timeout time.Duration `json:"timeout"`
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 22:07:20 +00:00
|
|
|
|
func (s *Shim) MarshalJSON() ([]byte, error) {
|
|
|
|
|
st := state{
|
|
|
|
|
Name: s.name,
|
|
|
|
|
Bundle: s.bundle,
|
|
|
|
|
Runtime: s.runtime.Name(),
|
|
|
|
|
RuntimeArgs: s.runtime.Args(),
|
2016-10-06 22:18:26 +00:00
|
|
|
|
RuntimeRoot: s.runtime.Root(),
|
2016-10-05 22:07:20 +00:00
|
|
|
|
NoPivotRoot: s.noPivotRoot,
|
|
|
|
|
Timeout: s.timeout,
|
2016-10-06 22:18:26 +00:00
|
|
|
|
Root: s.root,
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
return json.Marshal(st)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Shim) UnmarshalJSON(b []byte) error {
|
|
|
|
|
var st state
|
|
|
|
|
if err := json.Unmarshal(b, &st); err != nil {
|
|
|
|
|
return err
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
2016-10-06 22:18:26 +00:00
|
|
|
|
s.root = st.Root
|
2016-10-05 22:07:20 +00:00
|
|
|
|
s.name = st.Name
|
|
|
|
|
s.bundle = st.Bundle
|
|
|
|
|
s.timeout = st.Timeout
|
|
|
|
|
s.noPivotRoot = st.NoPivotRoot
|
|
|
|
|
r, err := oci.New(oci.Opts{
|
|
|
|
|
Name: st.Runtime,
|
|
|
|
|
Args: st.RuntimeArgs,
|
2016-10-06 22:18:26 +00:00
|
|
|
|
Root: st.RuntimeRoot,
|
2016-10-04 17:45:09 +00:00
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
2016-10-05 22:07:20 +00:00
|
|
|
|
return err
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
s.runtime = r
|
2016-10-06 18:39:12 +00:00
|
|
|
|
s.processes = make(map[string]*process)
|
2016-10-05 22:07:20 +00:00
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
func (s *Shim) Create(c *containerd.Container) (containerd.ProcessDelegate, error) {
|
2016-10-06 18:39:12 +00:00
|
|
|
|
s.bundle = c.Path()
|
2016-10-05 22:07:20 +00:00
|
|
|
|
var (
|
|
|
|
|
root = filepath.Join(s.root, "init")
|
|
|
|
|
cmd = s.command(c.ID(), c.Path(), s.runtime.Name())
|
|
|
|
|
)
|
2016-10-06 22:06:34 +00:00
|
|
|
|
if err := os.Mkdir(root, 0711); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-10-04 17:45:09 +00:00
|
|
|
|
// exec the shim inside the state directory setup with the process
|
|
|
|
|
// information for what is being run
|
2016-10-05 22:07:20 +00:00
|
|
|
|
cmd.Dir = root
|
2016-10-04 17:45:09 +00:00
|
|
|
|
// make sure the shim is in a new process group
|
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Setpgid: true,
|
|
|
|
|
}
|
2016-10-06 22:06:34 +00:00
|
|
|
|
p, err := s.startCommand(processOpts{
|
|
|
|
|
spec: c.Spec().Process,
|
|
|
|
|
root: root,
|
|
|
|
|
noPivotRoot: s.noPivotRoot,
|
|
|
|
|
checkpoint: s.checkpoint,
|
|
|
|
|
c: c,
|
|
|
|
|
cmd: cmd,
|
|
|
|
|
stdin: c.Stdin,
|
|
|
|
|
stdout: c.Stdout,
|
|
|
|
|
stderr: c.Stderr,
|
|
|
|
|
})
|
2016-10-04 17:45:09 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
s.pmu.Lock()
|
2016-10-05 22:07:20 +00:00
|
|
|
|
s.processes["init"] = p
|
2016-10-04 17:45:09 +00:00
|
|
|
|
s.pmu.Unlock()
|
2016-10-06 18:39:12 +00:00
|
|
|
|
f, err := os.Create(filepath.Join(s.root, "state.json"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
err = json.NewEncoder(f).Encode(s)
|
|
|
|
|
f.Close()
|
2016-10-04 17:45:09 +00:00
|
|
|
|
// ~TODO: oom and stats stuff here
|
2016-10-06 18:39:12 +00:00
|
|
|
|
return p, err
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
func (s *Shim) Start(c *containerd.Container) error {
|
2016-10-06 18:54:59 +00:00
|
|
|
|
p, err := s.getContainerInit()
|
2016-10-04 17:45:09 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
var (
|
|
|
|
|
errC = make(chan error, 1)
|
|
|
|
|
cmd = s.runtime.Command("start", c.ID())
|
|
|
|
|
)
|
|
|
|
|
go func() {
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err != nil {
|
|
|
|
|
errC <- fmt.Errorf("%s: %q", err, out)
|
|
|
|
|
}
|
|
|
|
|
errC <- nil
|
|
|
|
|
}()
|
|
|
|
|
select {
|
|
|
|
|
case err := <-errC:
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
case <-p.done:
|
|
|
|
|
if !p.success {
|
|
|
|
|
if cmd.Process != nil {
|
|
|
|
|
cmd.Process.Kill()
|
|
|
|
|
}
|
|
|
|
|
cmd.Wait()
|
|
|
|
|
return ErrShimExited
|
|
|
|
|
}
|
|
|
|
|
err := <-errC
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
func (s *Shim) Delete(c *containerd.Container) error {
|
2016-10-06 18:39:12 +00:00
|
|
|
|
if err := s.runtime.Delete(c); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return os.RemoveAll(s.root)
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
func (s *Shim) Exec(c *containerd.Container, p *containerd.Process) (containerd.ProcessDelegate, error) {
|
2016-10-06 22:06:34 +00:00
|
|
|
|
root, err := ioutil.TempDir(s.root, "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
cmd := s.command(c.ID(), c.Path(), s.runtime.Name())
|
|
|
|
|
// exec the shim inside the state directory setup with the process
|
|
|
|
|
// information for what is being run
|
|
|
|
|
cmd.Dir = root
|
|
|
|
|
// make sure the shim is in a new process group
|
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Setpgid: true,
|
|
|
|
|
}
|
|
|
|
|
sp, err := s.startCommand(processOpts{
|
|
|
|
|
exec: true,
|
|
|
|
|
spec: *p.Spec(),
|
|
|
|
|
root: root,
|
|
|
|
|
noPivotRoot: s.noPivotRoot,
|
|
|
|
|
checkpoint: s.checkpoint,
|
|
|
|
|
c: c,
|
|
|
|
|
cmd: cmd,
|
|
|
|
|
stdin: p.Stdin,
|
|
|
|
|
stdout: p.Stdout,
|
|
|
|
|
stderr: p.Stderr,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
s.pmu.Lock()
|
|
|
|
|
s.processes[filepath.Base(root)] = sp
|
|
|
|
|
s.pmu.Unlock()
|
|
|
|
|
return sp, nil
|
2016-10-06 18:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 18:47:47 +00:00
|
|
|
|
func (s *Shim) Load(id string) (containerd.ProcessDelegate, error) {
|
2016-10-06 18:54:59 +00:00
|
|
|
|
return s.getContainerInit()
|
2016-10-06 18:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 18:54:59 +00:00
|
|
|
|
func (s *Shim) getContainerInit() (*process, error) {
|
2016-10-04 17:45:09 +00:00
|
|
|
|
s.pmu.Lock()
|
2016-10-05 22:07:20 +00:00
|
|
|
|
p, ok := s.processes["init"]
|
2016-10-04 17:45:09 +00:00
|
|
|
|
s.pmu.Unlock()
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, errInitProcessNotExist
|
|
|
|
|
}
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 22:06:34 +00:00
|
|
|
|
func (s *Shim) startCommand(opts processOpts) (*process, error) {
|
|
|
|
|
p, err := newProcess(opts)
|
2016-10-05 22:07:20 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
2016-10-06 22:06:34 +00:00
|
|
|
|
if err := s.m.Add(p); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err := opts.cmd.Start(); err != nil {
|
2016-10-05 22:07:20 +00:00
|
|
|
|
close(p.done)
|
2016-10-04 17:45:09 +00:00
|
|
|
|
if checkShimNotFound(err) {
|
2016-10-05 22:07:20 +00:00
|
|
|
|
return nil, fmt.Errorf("%s not install on system", s.name)
|
2016-10-04 17:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
// make sure it does not die before we get the container's pid
|
|
|
|
|
defer func() {
|
|
|
|
|
go p.checkExited()
|
|
|
|
|
}()
|
2016-10-05 22:07:20 +00:00
|
|
|
|
if err := p.waitForCreate(s.timeout); err != nil {
|
2016-10-04 17:45:09 +00:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Shim) command(args ...string) *exec.Cmd {
|
|
|
|
|
return exec.Command(s.name, args...)
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 18:46:03 +00:00
|
|
|
|
func (s *Shim) startMonitor() {
|
2016-10-06 22:06:34 +00:00
|
|
|
|
go s.m.Run()
|
|
|
|
|
defer s.m.Close()
|
2016-10-06 18:46:03 +00:00
|
|
|
|
for m := range s.m.Events() {
|
|
|
|
|
p := m.(*process)
|
|
|
|
|
close(p.done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:45:09 +00:00
|
|
|
|
// checkShimNotFound checks the error returned from a exec call to see if the binary
|
|
|
|
|
// that was called exists on the system and returns true if the shim binary does not exist
|
|
|
|
|
func checkShimNotFound(err error) bool {
|
|
|
|
|
if exitError, ok := err.(*exec.Error); ok {
|
|
|
|
|
e := exitError.Err
|
|
|
|
|
return e == exec.ErrNotFound || e == os.ErrNotExist
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2016-10-05 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
// getFifoPath returns the path to the fifo on disk as long as the provided
|
|
|
|
|
// interface is an *os.File and has a valid path on the Name() method call
|
|
|
|
|
func getFifoPath(v interface{}) (string, error) {
|
|
|
|
|
f, ok := v.(*os.File)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", ErrNotFifo
|
|
|
|
|
}
|
|
|
|
|
p := f.Name()
|
|
|
|
|
if p == "" {
|
|
|
|
|
return "", ErrNotFifo
|
|
|
|
|
}
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getRootIDs(s *specs.Spec) (int, int, error) {
|
|
|
|
|
if s == nil {
|
|
|
|
|
return 0, 0, nil
|
|
|
|
|
}
|
|
|
|
|
var hasUserns bool
|
|
|
|
|
for _, ns := range s.Linux.Namespaces {
|
|
|
|
|
if ns.Type == specs.UserNamespace {
|
|
|
|
|
hasUserns = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !hasUserns {
|
|
|
|
|
return 0, 0, nil
|
|
|
|
|
}
|
|
|
|
|
uid := hostIDFromMap(0, s.Linux.UIDMappings)
|
|
|
|
|
gid := hostIDFromMap(0, s.Linux.GIDMappings)
|
|
|
|
|
return uid, gid, nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 22:51:31 +00:00
|
|
|
|
func hostIDFromMap(id uint32, mp []specs.LinuxIDMapping) int {
|
2016-10-05 22:07:20 +00:00
|
|
|
|
for _, m := range mp {
|
|
|
|
|
if (id >= m.ContainerID) && (id <= (m.ContainerID + m.Size - 1)) {
|
|
|
|
|
return int(m.HostID + (id - m.ContainerID))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|