@@ -47,30 +47,54 @@ type network struct {
4747 TempVethPeerName string `json:"temp_veth_peer_name"`
4848}
4949
50- // initConfig is used for transferring parameters from Exec() to Init()
50+ // initConfig is used for transferring parameters from Exec() to Init().
51+ // It contains:
52+ // - original container config;
53+ // - some [Process] properties;
54+ // - set of properties merged from the container config ([configs.Config])
55+ // and the process ([Process]);
56+ // - some properties that come from the container.
57+ //
58+ // When adding new fields, please make sure they go into the relevant section.
5159type initConfig struct {
52- Args []string `json:"args"`
53- Env []string `json:"env"`
54- Cwd string `json:"cwd"`
55- Capabilities * configs.Capabilities `json:"capabilities"`
56- ProcessLabel string `json:"process_label"`
57- AppArmorProfile string `json:"apparmor_profile"`
58- NoNewPrivileges bool `json:"no_new_privileges"`
59- UID int `json:"uid"`
60- GID int `json:"gid"`
61- AdditionalGroups []int `json:"additional_groups"`
62- Config * configs.Config `json:"config"`
63- Networks []* network `json:"network"`
64- PassedFilesCount int `json:"passed_files_count"`
65- ContainerID string `json:"containerid"`
66- Rlimits []configs.Rlimit `json:"rlimits"`
67- CreateConsole bool `json:"create_console"`
68- ConsoleWidth uint16 `json:"console_width"`
69- ConsoleHeight uint16 `json:"console_height"`
70- RootlessEUID bool `json:"rootless_euid,omitempty"`
71- RootlessCgroups bool `json:"rootless_cgroups,omitempty"`
72- SpecState * specs.State `json:"spec_state,omitempty"`
73- Cgroup2Path string `json:"cgroup2_path,omitempty"`
60+ // Config is the original container config.
61+ Config * configs.Config `json:"config"`
62+
63+ // Properties that are unique to and come from [Process].
64+
65+ Args []string `json:"args"`
66+ Env []string `json:"env"`
67+ UID int `json:"uid"`
68+ GID int `json:"gid"`
69+ AdditionalGroups []int `json:"additional_groups"`
70+ Cwd string `json:"cwd"`
71+ CreateConsole bool `json:"create_console"`
72+ ConsoleWidth uint16 `json:"console_width"`
73+ ConsoleHeight uint16 `json:"console_height"`
74+ PassedFilesCount int `json:"passed_files_count"`
75+
76+ // Properties that exists both in the container config and the process,
77+ // as merged by [Container.newInitConfig] (process properties has preference).
78+
79+ AppArmorProfile string `json:"apparmor_profile"`
80+ Capabilities * configs.Capabilities `json:"capabilities"`
81+ NoNewPrivileges bool `json:"no_new_privileges"`
82+ ProcessLabel string `json:"process_label"`
83+ Rlimits []configs.Rlimit `json:"rlimits"`
84+ IOPriority * configs.IOPriority `json:"io_priority,omitempty"`
85+ Scheduler * configs.Scheduler `json:"scheduler,omitempty"`
86+
87+ // Miscellaneous properties, filled in by [Container.newInitConfig]
88+ // unless documented otherwise.
89+
90+ ContainerID string `json:"containerid"`
91+ Cgroup2Path string `json:"cgroup2_path,omitempty"`
92+
93+ // Networks is filled in from container config by [initProcess.createNetworkInterfaces].
94+ Networks []* network `json:"network"`
95+
96+ // SpecState is filled in by [initProcess.Start].
97+ SpecState * specs.State `json:"spec_state,omitempty"`
7498}
7599
76100// Init is part of "runc init" implementation.
@@ -300,13 +324,7 @@ func finalizeNamespace(config *initConfig) error {
300324 }
301325 }
302326
303- caps := & configs.Capabilities {}
304- if config .Capabilities != nil {
305- caps = config .Capabilities
306- } else if config .Config .Capabilities != nil {
307- caps = config .Config .Capabilities
308- }
309- w , err := capabilities .New (caps )
327+ w , err := capabilities .New (config .Capabilities )
310328 if err != nil {
311329 return err
312330 }
@@ -456,7 +474,7 @@ func setupUser(config *initConfig) error {
456474 // There's nothing we can do about /etc/group entries, so we silently
457475 // ignore setting groups here (since the user didn't explicitly ask us to
458476 // set the group).
459- allowSupGroups := ! config .RootlessEUID && string (bytes .TrimSpace (setgroups )) != "deny"
477+ allowSupGroups := ! config .Config . RootlessEUID && string (bytes .TrimSpace (setgroups )) != "deny"
460478
461479 if allowSupGroups {
462480 if err := unix .Setgroups (config .AdditionalGroups ); err != nil {
@@ -590,7 +608,7 @@ func setupRlimits(limits []configs.Rlimit, pid int) error {
590608 return nil
591609}
592610
593- func setupScheduler (config * configs. Config ) error {
611+ func setupScheduler (config * initConfig ) error {
594612 if config .Scheduler == nil {
595613 return nil
596614 }
@@ -599,15 +617,15 @@ func setupScheduler(config *configs.Config) error {
599617 return err
600618 }
601619 if err := unix .SchedSetAttr (0 , attr , 0 ); err != nil {
602- if errors .Is (err , unix .EPERM ) && config .Cgroups .CpusetCpus != "" {
620+ if errors .Is (err , unix .EPERM ) && config .Config . Cgroups .CpusetCpus != "" {
603621 return errors .New ("process scheduler can't be used together with AllowedCPUs" )
604622 }
605623 return fmt .Errorf ("error setting scheduler: %w" , err )
606624 }
607625 return nil
608626}
609627
610- func setupIOPriority (config * configs. Config ) error {
628+ func setupIOPriority (config * initConfig ) error {
611629 const ioprioWhoPgrp = 1
612630
613631 ioprio := config .IOPriority
0 commit comments