diff options
| author | Joey Jiao <joeyjiaojg@qq.com> | 2023-07-02 12:14:03 +0800 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-07-04 16:43:58 +0000 |
| commit | 9a97070da62577e730aaaae4cf657900abb16957 (patch) | |
| tree | bc3b5d3eaddd3d9036c1302e59cbb64b6c52cd58 /pkg/host/machine_info_linux.go | |
| parent | db33bc12e4f969af9479eb1c55d6a5ed2050b9b5 (diff) | |
pkg/host: export ParseModulesText
Change-Id: I3119aed5cfe223e24cfc56b27612adaf2a638a99
Diffstat (limited to 'pkg/host/machine_info_linux.go')
| -rw-r--r-- | pkg/host/machine_info_linux.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pkg/host/machine_info_linux.go b/pkg/host/machine_info_linux.go index 702b55cb3..d46dacd4e 100644 --- a/pkg/host/machine_info_linux.go +++ b/pkg/host/machine_info_linux.go @@ -21,6 +21,7 @@ func init() { } machineModulesInfo = getModulesInfo machineGlobsInfo = getGlobsInfo + machineParseModules = parseModules } func readCPUInfo(buffer *bytes.Buffer) error { @@ -125,8 +126,12 @@ func readKVMInfo(buffer *bytes.Buffer) error { } func getModulesInfo() ([]KernelModule, error) { - var modules []KernelModule modulesText, _ := os.ReadFile("/proc/modules") + return parseModules(modulesText) +} + +func parseModules(modulesText []byte) ([]KernelModule, error) { + var modules []KernelModule re := regexp.MustCompile(`(\w+) ([0-9]+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`) for _, m := range re.FindAllSubmatch(modulesText, -1) { addr, err := strconv.ParseUint(string(m[3]), 0, 64) |
