fix panic regression when config doesnt have caps
When process config doesnt specify capabilities anywhere, we should not panic because setting capabilities are optional. Signed-off-by: Daniel Dao <dqminh89@gmail.com>
This commit is contained in:
parent
767783a631
commit
09c72cea69
|
@ -119,9 +119,11 @@ func finalizeNamespace(config *initConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilities := config.Config.Capabilities
|
capabilities := &configs.Capabilities{}
|
||||||
if config.Capabilities != nil {
|
if config.Capabilities != nil {
|
||||||
capabilities = config.Capabilities
|
capabilities = config.Capabilities
|
||||||
|
} else if config.Config.Capabilities != nil {
|
||||||
|
capabilities = config.Config.Capabilities
|
||||||
}
|
}
|
||||||
w, err := newContainerCapList(capabilities)
|
w, err := newContainerCapList(capabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -339,6 +339,57 @@ func TestProcessEnv(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessEmptyCaps(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
root, err := newTestRoot()
|
||||||
|
ok(t, err)
|
||||||
|
defer os.RemoveAll(root)
|
||||||
|
|
||||||
|
rootfs, err := newRootfs()
|
||||||
|
ok(t, err)
|
||||||
|
defer remove(rootfs)
|
||||||
|
|
||||||
|
config := newTemplateConfig(rootfs)
|
||||||
|
config.Capabilities = nil
|
||||||
|
|
||||||
|
container, err := factory.Create("test", config)
|
||||||
|
ok(t, err)
|
||||||
|
defer container.Destroy()
|
||||||
|
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
pconfig := libcontainer.Process{
|
||||||
|
Cwd: "/",
|
||||||
|
Args: []string{"sh", "-c", "cat /proc/self/status"},
|
||||||
|
Env: standardEnvironment,
|
||||||
|
Stdin: nil,
|
||||||
|
Stdout: &stdout,
|
||||||
|
}
|
||||||
|
err = container.Run(&pconfig)
|
||||||
|
ok(t, err)
|
||||||
|
|
||||||
|
// Wait for process
|
||||||
|
waitProcess(&pconfig, t)
|
||||||
|
|
||||||
|
outputStatus := string(stdout.Bytes())
|
||||||
|
|
||||||
|
lines := strings.Split(outputStatus, "\n")
|
||||||
|
|
||||||
|
effectiveCapsLine := ""
|
||||||
|
for _, l := range lines {
|
||||||
|
line := strings.TrimSpace(l)
|
||||||
|
if strings.Contains(line, "CapEff:") {
|
||||||
|
effectiveCapsLine = line
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if effectiveCapsLine == "" {
|
||||||
|
t.Fatal("Couldn't find effective caps: ", outputStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessCaps(t *testing.T) {
|
func TestProcessCaps(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue