MCPcopy Create free account
hub / github.com/containerd/fifo / getHandle

Function getHandle

handle_linux.go:40–71  ·  view source on GitHub ↗
(fn string)

Source from the content-addressed store, hash-verified

38}
39
40func getHandle(fn string) (*handle, error) {
41 f, err := os.OpenFile(fn, O_PATH, 0)
42 if err != nil {
43 return nil, fmt.Errorf("failed to open %v with O_PATH: %w", fn, err)
44 }
45
46 var (
47 stat syscall.Stat_t
48 fd = f.Fd()
49 )
50 if err := syscall.Fstat(int(fd), &stat); err != nil {
51 f.Close()
52 return nil, fmt.Errorf("failed to stat handle %v: %w", fd, err)
53 }
54
55 h := &handle{
56 f: f,
57 name: fn,
58 //nolint:unconvert
59 dev: uint64(stat.Dev),
60 ino: stat.Ino,
61 fd: fd,
62 }
63
64 // check /proc just in case
65 if _, err := os.Stat(h.procPath()); err != nil {
66 f.Close()
67 return nil, fmt.Errorf("couldn't stat %v: %w", h.procPath(), err)
68 }
69
70 return h, nil
71}
72
73func (h *handle) procPath() string {
74 return fmt.Sprintf("/proc/self/fd/%d", h.fd)

Callers 1

openFifoFunction · 0.70

Calls 2

procPathMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…