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

Function getNetNSPath

pkg/ocihook/ocihook.go:307–328  ·  view source on GitHub ↗
(state *specs.State)

Source from the content-addressed store, hash-verified

305}
306
307func getNetNSPath(state *specs.State) (string, error) {
308 // If we have a network-namespace annotation we use it over the passed Pid.
309 netNsPath, netNsFound := state.Annotations[NetworkNamespace]
310 if netNsFound {
311 if _, err := os.Stat(netNsPath); err != nil {
312 return "", err
313 }
314
315 return netNsPath, nil
316 }
317
318 if state.Pid == 0 {
319 return "", errors.New("both state.Pid and the netNs annotation are unset")
320 }
321
322 // We dont't have a networking namespace annotation, but we have a PID.
323 s := fmt.Sprintf("/proc/%d/ns/net", state.Pid)
324 if _, err := os.Stat(s); err != nil {
325 return "", err
326 }
327 return s, nil
328}
329
330func getPortMapOpts(opts *handlerOpts) ([]cni.NamespaceOpts, error) {
331 if len(opts.ports) > 0 {

Callers 1

applyNetworkSettingsFunction · 0.85

Calls 1

StatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…