MCPcopy
hub / github.com/opencontainers/runc / getProcess

Function getProcess

exec.go:196–281  ·  view source on GitHub ↗
(context *cli.Context, c *libcontainer.Container)

Source from the content-addressed store, hash-verified

194}
195
196func getProcess(context *cli.Context, c *libcontainer.Container) (*specs.Process, error) {
197 if path := context.String("process"); path != "" {
198 f, err := os.Open(path)
199 if err != nil {
200 return nil, err
201 }
202 defer f.Close()
203 var p specs.Process
204 if err := json.NewDecoder(f).Decode(&p); err != nil {
205 return nil, err
206 }
207 return &p, validateProcessSpec(&p)
208 }
209 // Process from config.json and CLI flags.
210 bundle, ok := utils.SearchLabels(c.Config().Labels, "bundle")
211 if !ok {
212 return nil, errors.New("bundle not found in labels")
213 }
214 if err := os.Chdir(bundle); err != nil {
215 return nil, err
216 }
217 spec, err := loadSpec(specConfig)
218 if err != nil {
219 return nil, err
220 }
221 p := spec.Process
222 args := context.Args()
223 if len(args) < 2 {
224 return nil, errors.New("exec args cannot be empty")
225 }
226 p.Args = args[1:]
227 // Override the cwd, if passed.
228 if cwd := context.String("cwd"); cwd != "" {
229 p.Cwd = cwd
230 }
231 if ap := context.String("apparmor"); ap != "" {
232 p.ApparmorProfile = ap
233 }
234 if l := context.String("process-label"); l != "" {
235 p.SelinuxLabel = l
236 }
237 if caps := context.StringSlice("cap"); len(caps) > 0 {
238 for _, c := range caps {
239 p.Capabilities.Bounding = append(p.Capabilities.Bounding, c)
240 p.Capabilities.Effective = append(p.Capabilities.Effective, c)
241 p.Capabilities.Permitted = append(p.Capabilities.Permitted, c)
242 // Since ambient capabilities can't be set without inherritable,
243 // and runc exec --cap don't set inheritable, let's only set
244 // ambient if we already have some inheritable bits set from spec.
245 if p.Capabilities.Inheritable != nil {
246 p.Capabilities.Ambient = append(p.Capabilities.Ambient, c)
247 }
248 }
249 }
250 // append the passed env variables
251 p.Env = append(p.Env, context.StringSlice("env")...)
252
253 // Always set tty to false, unless explicitly enabled from CLI.

Callers 1

execProcessFunction · 0.85

Calls 6

SearchLabelsFunction · 0.92
validateProcessSpecFunction · 0.85
loadSpecFunction · 0.85
ConfigMethod · 0.80
StringMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…