Skip to content

Commit

Permalink
Merge pull request #30 from Jackson-Greene/kernel-module-parsing-fixes
Browse files Browse the repository at this point in the history
Fix kernel module parsing when flags are present
  • Loading branch information
brancz authored Jan 13, 2025
2 parents fa444a2 + 65e98ce commit 8c64051
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions proc/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ type kernelModule struct {
}

func parseKernelModuleLine(line string) (kernelModule, error) {
// The format is: "name size refcount dependencies state address"
parts := strings.SplitN(line, " ", 6)
// The format is: "name size refcount dependencies state address flags"
parts := strings.SplitN(line, " ", 7)

// At least 6 parts are expected (flags are not always present and are not needed here)
if len(parts) < 6 {
return kernelModule{}, fmt.Errorf("unexpected line in modules: '%s'", line)
}
Expand Down
10 changes: 8 additions & 2 deletions proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ ahci 45056 - - Live 0xffffffffc0294000
libahci 49152 - - Live 0xffffffffc027f000
sp5100_tco 12288 - - Live 0xffffffffc0274000
watchdog 40960 - - Live 0xffffffffc025f000
k10temp 12288 - - Live 0xffffffffc0254000`)
k10temp 12288 - - Live 0xffffffffc0254000
vboxguest 499712 - - Live 0xffffffffc097d000 (OE)`)

kmods, err := parseKernelModules(bufio.NewScanner(bytes.NewReader(content)))
require.NoError(t, err)

require.Len(t, kmods, 7)
require.Len(t, kmods, 8)
require.Equal(t, []kernelModule{
{
name: "i40e",
Expand Down Expand Up @@ -90,6 +91,11 @@ k10temp 12288 - - Live 0xffffffffc0254000`)
size: 12288,
address: 0xffffffffc0254000,
},
{
name: "vboxguest",
size: 499712,
address: 0xffffffffc097d000,
},
}, kmods)
}

Expand Down

0 comments on commit 8c64051

Please sign in to comment.