浏览文件
bootsession_linux.go
20 行 · 510 B历史下载| 1 | // SPDX-FileCopyrightText: Copyright The Lima Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package osutil |
| 5 | |
| 6 | import ( |
| 7 | "os" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | // BootSessionID returns an identifier of the current boot of the host. |
| 12 | // The identifier changes on every reboot, so it can be used to detect state that was left |
| 13 | // behind by a previous boot. |
| 14 | func BootSessionID() (string, error) { |
| 15 | b, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| 16 | if err != nil { |
| 17 | return "", err |
| 18 | } |
| 19 | return strings.TrimSpace(string(b)), nil |
| 20 | } |

