Skip to content

Commit 73849e7

Browse files
committed
libct: simplify Caps inheritance
For all other properties that are available in both Config and Process, the merging is performed by newInitConfig. Let's do the same for Capabilities for the sake of code uniformity. Also, thanks to the previous commit, we no longer have to make sure we do not call capabilities.New(nil). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 049a5f7 commit 73849e7

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

libcontainer/container_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
700700
GID: process.GID,
701701
AdditionalGroups: process.AdditionalGroups,
702702
Cwd: process.Cwd,
703-
Capabilities: process.Capabilities,
703+
Capabilities: c.config.Capabilities,
704704
PassedFilesCount: len(process.ExtraFiles),
705705
ContainerID: c.ID(),
706706
NoNewPrivileges: c.config.NoNewPrivileges,
@@ -714,6 +714,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
714714

715715
// Overwrite config properties with ones from process.
716716

717+
if process.Capabilities != nil {
718+
cfg.Capabilities = process.Capabilities
719+
}
717720
if process.NoNewPrivileges != nil {
718721
cfg.NoNewPrivileges = *process.NoNewPrivileges
719722
}

libcontainer/init_linux.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,7 @@ func finalizeNamespace(config *initConfig) error {
322322
}
323323
}
324324

325-
caps := &configs.Capabilities{}
326-
if config.Capabilities != nil {
327-
caps = config.Capabilities
328-
} else if config.Config.Capabilities != nil {
329-
caps = config.Config.Capabilities
330-
}
331-
w, err := capabilities.New(caps)
325+
w, err := capabilities.New(config.Capabilities)
332326
if err != nil {
333327
return err
334328
}

0 commit comments

Comments
 (0)