Skip to content

Commit

Permalink
helpers/kernel_config: kernel_features refactoring
Browse files Browse the repository at this point in the history
- kernel_features: renamed to kernel_config (the type name)
- kernel_config: LIBBPFGO_KCONFIG_FILE env variable logic

Reference: #60
Reference: #61
  • Loading branch information
rafaeldtinoco authored and Rafael David Tinoco committed Sep 2, 2021
1 parent 59c9cc3 commit 95380e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions helpers/kernel_features.go → helpers/kernel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,20 @@ type KernelConfig struct {
}

// InitKernelConfig inits external KernelConfig object
func InitKernelConfig(OSKConfigFilePath string) (*KernelConfig, error) {
func InitKernelConfig() (*KernelConfig, error) {
config := KernelConfig{}

// special case: user provided kconfig file (it MUST exist)
if len(OSKConfigFilePath) > 2 {
if _, err := os.Stat(OSKConfigFilePath); err != nil {
osKConfigFilePath, err := checkEnvPath("LIBBPFGO_KCONFIG_FILE") // override /proc/config.gz or /boot/config-$(uname -r) if needed (containers)
if err != nil {
return nil, err
}
if len(osKConfigFilePath) > 2 {
if _, err := os.Stat(osKConfigFilePath); err != nil {
return nil, err
}
config.KConfigFilePath = OSKConfigFilePath // user might need to know used KConfig file in order to override kconfig for libbpf (example)
if err := config.initKernelConfig(OSKConfigFilePath); err != nil {
config.KConfigFilePath = osKConfigFilePath // user might need to know used KConfig file in order to override kconfig for libbpf (example)
if err := config.initKernelConfig(osKConfigFilePath); err != nil {
return nil, err
}

Expand All @@ -206,14 +210,12 @@ func InitKernelConfig(OSKConfigFilePath string) (*KernelConfig, error) {
} // ignore if /proc/config.gz does not exist

// slowerpath: /boot/$(uname -r)

releaseVersion, err := UnameRelease()
if err != nil {
return nil, err
}
releaseFilePath := fmt.Sprintf("/boot/config-%s", releaseVersion)
config.KConfigFilePath = releaseFilePath // and here

if err := config.initKernelConfig(releaseFilePath); err != nil {
return nil, err
}
Expand Down
File renamed without changes.

0 comments on commit 95380e5

Please sign in to comment.