MCPcopy Create free account
hub / github.com/subtrace/subtrace / findUsername

Function findUsername

cmd/run/engine/process/process.go:294–314  ·  view source on GitHub ↗
(uid uint32)

Source from the content-addressed store, hash-verified

292}
293
294func findUsername(uid uint32) (string, error) {
295 b, err := os.ReadFile("/etc/passwd")
296 if err != nil {
297 return "", fmt.Errorf("read file: %w", err)
298 }
299
300 for _, line := range strings.Split(string(b), "\n") {
301 parts := strings.Split(line, ":")
302 if len(parts) != 7 {
303 continue
304 }
305 parsed, err := strconv.Atoi(parts[2])
306 if err != nil {
307 continue
308 }
309 if parsed == int(uid) {
310 return parts[0], nil
311 }
312 }
313 return "", fmt.Errorf("not found")
314}
315
316func htons(x uint16) uint16 { return (x&0xff)<<8 | (x >> 8) }

Callers 1

getEventTemplateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected