| 1 | package cage |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "os" |
| 6 | "strconv" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | |
| 12 | func processStartToken(pid int) string { |
| 13 | if pid <= 0 { |
| 14 | return "" |
| 15 | } |
| 16 | boot, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| 17 | if err != nil { |
| 18 | return "" |
| 19 | } |
| 20 | stat, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/stat") |
| 21 | if err != nil { |
| 22 | return "" |
| 23 | } |
| 24 | |
| 25 | |
| 26 | i := bytes.LastIndexByte(stat, ')') |
| 27 | if i < 0 { |
| 28 | return "" |
| 29 | } |
| 30 | fields := strings.Fields(string(stat[i+1:])) |
| 31 | if len(fields) < 20 { |
| 32 | return "" |
| 33 | } |
| 34 | return strings.TrimSpace(string(boot)) + ":" + fields[19] |
| 35 | } |