Debian Codegraph @

internal/linux/version.go

raw symbols SCIP
1 package linux
2
3 import (
4 "fmt"
5 "sync"
6
7 "github.com/cilium/ebpf/internal"
8 "github.com/cilium/ebpf/internal/unix"
9 )
10
11 // KernelVersion returns the version of the currently running kernel.
12 var KernelVersion = sync.OnceValues(detectKernelVersion)
13
14 // detectKernelVersion returns the version of the running kernel.
15 func detectKernelVersion() (internal.Version, error) {
16 vc, err := vdsoVersion()
17 if err != nil {
18 return internal.Version{}, err
19 }
20 return internal.NewVersionFromCode(vc), nil
21 }
22
23 // KernelRelease returns the release string of the running kernel.
24 // Its format depends on the Linux distribution and corresponds to directory
25 // names in /lib/modules by convention. Some examples are 5.15.17-1-lts and
26 // 4.19.0-16-amd64.
27 func KernelRelease() (string, error) {
28 var uname unix.Utsname
29 if err := unix.Uname(&uname); err != nil {
30 return "", fmt.Errorf("uname failed: %w", err)
31 }
32
33 return unix.ByteSliceToString(uname.Release[:]), nil
34 }