From 95380e5a0040b0352e9a44552e9d47432a815d54 Mon Sep 17 00:00:00 2001 From: Rafael David Tinoco Date: Thu, 2 Sep 2021 15:59:36 -0300 Subject: [PATCH] helpers/kernel_config: kernel_features refactoring - kernel_features: renamed to kernel_config (the type name) - kernel_config: LIBBPFGO_KCONFIG_FILE env variable logic Reference: https://github.com/aquasecurity/libbpfgo/issues/60 Reference: https://github.com/aquasecurity/libbpfgo/issues/61 --- helpers/{kernel_features.go => kernel_config.go} | 16 +++++++++------- ...el_features_test.go => kernel_config_test.go} | 0 2 files changed, 9 insertions(+), 7 deletions(-) rename helpers/{kernel_features.go => kernel_config.go} (96%) rename helpers/{kernel_features_test.go => kernel_config_test.go} (100%) diff --git a/helpers/kernel_features.go b/helpers/kernel_config.go similarity index 96% rename from helpers/kernel_features.go rename to helpers/kernel_config.go index b73c6daf..cfba42b3 100644 --- a/helpers/kernel_features.go +++ b/helpers/kernel_config.go @@ -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 } @@ -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 } diff --git a/helpers/kernel_features_test.go b/helpers/kernel_config_test.go similarity index 100% rename from helpers/kernel_features_test.go rename to helpers/kernel_config_test.go