| @@ -0,0 +1,32 @@ |
| | 1 | +// Package hostkernel reports facts about the kernel the current process |
| | 2 | +// runs on. Linux 4.19 specific workarounds check IsLinux419 so that other |
| | 3 | +// kernels keep the upstream behavior. |
| | 4 | +package hostkernel |
| | 5 | + |
| | 6 | +import ( |
| | 7 | + "strings" |
| | 8 | + "sync" |
| | 9 | + |
| | 10 | + "golang.org/x/sys/unix" |
| | 11 | +) |
| | 12 | + |
| | 13 | +// IsLinux419 reports whether the host kernel is Linux 4.19 (e.g. openEuler |
| | 14 | +// 20.03 LTS). The result is computed once and cached. |
| | 15 | +func IsLinux419() bool { |
| | 16 | + return isLinux419() |
| | 17 | +} |
| | 18 | + |
| | 19 | +var isLinux419 = sync.OnceValue(func() bool { |
| | 20 | + var uts unix.Utsname |
| | 21 | + if err := unix.Uname(&uts); err != nil { |
| | 22 | + return false |
| | 23 | + } |
| | 24 | + |
| | 25 | + return isLinux419Release(unix.ByteSliceToString(uts.Release[:])) |
| | 26 | +}) |
| | 27 | + |
| | 28 | +// isLinux419Release reports whether a kernel release string, as printed by |
| | 29 | +// `uname -r`, belongs to Linux 4.19. |
| | 30 | +func isLinux419Release(release string) bool { |
| | 31 | + return release == "4.19" || strings.HasPrefix(release, "4.19.") |
| | 32 | +} |