MCPcopy Create free account
hub / github.com/containerd/nerdctl / generatePIDOpts

Function generatePIDOpts

pkg/cmd/container/run_linux.go:176–223  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, pid string)

Source from the content-addressed store, hash-verified

174}
175
176func generatePIDOpts(ctx context.Context, client *containerd.Client, pid string) ([]oci.SpecOpts, string, error) {
177 opts := make([]oci.SpecOpts, 0)
178 pid = strings.ToLower(pid)
179 var pidInternalLabel string
180
181 switch pid {
182 case "":
183 // do nothing
184 case "host":
185 opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace))
186 if rootlessutil.IsRootless() {
187 opts = append(opts, containerutil.WithBindMountHostProcfs)
188 }
189 default: // container:<id|name>
190 parsed := strings.Split(pid, ":")
191 if len(parsed) < 2 || parsed[0] != "container" {
192 return nil, "", fmt.Errorf("invalid pid namespace. Set --pid=[host|container:<name|id>")
193 }
194
195 containerName := parsed[1]
196 walker := &containerwalker.ContainerWalker{
197 Client: client,
198 OnFound: func(ctx context.Context, found containerwalker.Found) error {
199 if found.MatchCount > 1 {
200 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
201 }
202
203 o, err := containerutil.GenerateSharingPIDOpts(ctx, found.Container)
204 if err != nil {
205 return err
206 }
207 opts = append(opts, o...)
208 pidInternalLabel = found.Container.ID()
209
210 return nil
211 },
212 }
213 matchedCount, err := walker.Walk(ctx, containerName)
214 if err != nil {
215 return nil, "", err
216 }
217 if matchedCount < 1 {
218 return nil, "", fmt.Errorf("no such container: %s", containerName)
219 }
220 }
221
222 return opts, pidInternalLabel, nil
223}
224
225func setOOMScoreAdj(opts []oci.SpecOpts, oomScoreAdjChanged bool, oomScoreAdj int) ([]oci.SpecOpts, error) {
226 if !oomScoreAdjChanged {

Callers 1

generateNamespaceOptsFunction · 0.85

Calls 3

WalkMethod · 0.95
IsRootlessFunction · 0.92
GenerateSharingPIDOptsFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…