Debian Codegraph @

internal/linux/kconfig.go

raw symbols SCIP
1 package linux
2
3 import (
4 "fmt"
5 "os"
6 )
7
8 // FindKConfig searches for a kconfig file on the host.
9 //
10 // It first reads from /boot/config- of the current running kernel and tries
11 // /proc/config.gz if nothing was found in /boot.
12 // If none of the file provide a kconfig, it returns an error.
13 func FindKConfig() (*os.File, error) {
14 kernelRelease, err := KernelRelease()
15 if err != nil {
16 return nil, fmt.Errorf("cannot get kernel release: %w", err)
17 }
18
19 path := "/boot/config-" + kernelRelease
20 f, err := os.Open(path)
21 if err == nil {
22 return f, nil
23 }
24
25 f, err = os.Open("/proc/config.gz")
26 if err == nil {
27 return f, nil
28 }
29
30 return nil, fmt.Errorf("neither %s nor /proc/config.gz provide a kconfig", path)
31 }