File tree 3 files changed +33
-27
lines changed
3 files changed +33
-27
lines changed Original file line number Diff line number Diff line change @@ -652,7 +652,7 @@ func resolveKconfig(m *MapSpec) error {
652
652
653
653
// We only parse kconfig file if a CONFIG_* variable was found.
654
654
if len (configs ) > 0 {
655
- f , err := kconfig . Find ()
655
+ f , err := linux . FindKConfig ()
656
656
if err != nil {
657
657
return fmt .Errorf ("cannot find a kconfig file: %w" , err )
658
658
}
Original file line number Diff line number Diff line change
1
+ // Package kconfig implements a parser for the format of Linux's .config file.
1
2
package kconfig
2
3
3
4
import (
@@ -7,39 +8,13 @@ import (
7
8
"fmt"
8
9
"io"
9
10
"math"
10
- "os"
11
11
"strconv"
12
12
"strings"
13
13
14
14
"github.com/cilium/ebpf/btf"
15
15
"github.com/cilium/ebpf/internal"
16
- "github.com/cilium/ebpf/internal/linux"
17
16
)
18
17
19
- // Find find a kconfig file on the host.
20
- // It first reads from /boot/config- of the current running kernel and tries
21
- // /proc/config.gz if nothing was found in /boot.
22
- // If none of the file provide a kconfig, it returns an error.
23
- func Find () (* os.File , error ) {
24
- kernelRelease , err := linux .KernelRelease ()
25
- if err != nil {
26
- return nil , fmt .Errorf ("cannot get kernel release: %w" , err )
27
- }
28
-
29
- path := "/boot/config-" + kernelRelease
30
- f , err := os .Open (path )
31
- if err == nil {
32
- return f , nil
33
- }
34
-
35
- f , err = os .Open ("/proc/config.gz" )
36
- if err == nil {
37
- return f , nil
38
- }
39
-
40
- return nil , fmt .Errorf ("neither %s nor /proc/config.gz provide a kconfig" , path )
41
- }
42
-
43
18
// Parse parses the kconfig file for which a reader is given.
44
19
// All the CONFIG_* which are in filter and which are set set will be
45
20
// put in the returned map as key with their corresponding value as map value.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments