ProcThreadSelfOpen is a wrapper around [procfs.Handle.OpenThreadSelf] and [pathrs.Reopen], to let you one-shot open a procfs file with the given flags. The returned [procfs.ProcThreadSelfCloser] needs the same handling as when using pathrs-lite.
(subpath string, flags int)
| 72 | // flags. The returned [procfs.ProcThreadSelfCloser] needs the same handling as |
| 73 | // when using pathrs-lite. |
| 74 | func ProcThreadSelfOpen(subpath string, flags int) (_ *os.File, _ procfs.ProcThreadSelfCloser, Err error) { |
| 75 | proc, err := retryEAGAIN(procfs.OpenProcRoot) |
| 76 | if err != nil { |
| 77 | return nil, nil, err |
| 78 | } |
| 79 | defer proc.Close() |
| 80 | |
| 81 | handle, closer, err := retryEAGAIN2(func() (*os.File, procfs.ProcThreadSelfCloser, error) { |
| 82 | return proc.OpenThreadSelf(subpath) |
| 83 | }) |
| 84 | if err != nil { |
| 85 | return nil, nil, err |
| 86 | } |
| 87 | if closer != nil { |
| 88 | defer func() { |
| 89 | if Err != nil { |
| 90 | closer() |
| 91 | } |
| 92 | }() |
| 93 | } |
| 94 | defer handle.Close() |
| 95 | |
| 96 | f, err := Reopen(handle, flags) |
| 97 | if err != nil { |
| 98 | return nil, nil, fmt.Errorf("reopen %s: %w", handle.Name(), err) |
| 99 | } |
| 100 | return f, closer, nil |
| 101 | } |
| 102 | |
| 103 | // Reopen is a wrapper around pathrs.Reopen. |
| 104 | func Reopen(file *os.File, flags int) (*os.File, error) { |
searching dependent graphs…