()
| 263 | } |
| 264 | |
| 265 | func (p *Process) cleanup() { |
| 266 | // TODO: is this right? what if a FD we hold is held by another process with |
| 267 | // a dup+sendmsg or a pidfd_getfd? |
| 268 | <-p.Exited |
| 269 | |
| 270 | p.mu.RLock() |
| 271 | defer p.mu.RUnlock() |
| 272 | var errs []error |
| 273 | for fd, s := range p.sockets { |
| 274 | if errno := s.Close(); errno != 0 { |
| 275 | errs = append(errs, fmt.Errorf("close socket fd=targfd_%d: %w", fd, errno)) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if !p.pidfd.ClosingIncRef() { |
| 280 | errs = append(errs, fmt.Errorf("pidfd: already closed")) |
| 281 | } else { |
| 282 | defer p.pidfd.DecRef() |
| 283 | p.pidfd.Lock() |
| 284 | if err := unix.Close(p.pidfd.FD()); err != nil { |
| 285 | errs = append(errs, fmt.Errorf("pidfd: close: %w", err)) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | for idx, err := range errs { |
| 290 | slog.Error("failed to clean up process", "process", p, "idx", idx, "err", err) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | func findUsername(uid uint32) (string, error) { |
| 295 | b, err := os.ReadFile("/etc/passwd") |
no test coverage detected