MCPcopy Index your code
hub / github.com/subtrace/subtrace / cleanup

Method cleanup

cmd/run/engine/process/process.go:265–292  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

263}
264
265func (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
294func findUsername(uid uint32) (string, error) {
295 b, err := os.ReadFile("/etc/passwd")

Callers 3

handleExitMethod · 0.95
handleExitGroupMethod · 0.95
WaitMethod · 0.95

Calls 5

ClosingIncRefMethod · 0.80
DecRefMethod · 0.80
LockMethod · 0.80
FDMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected