Skip to content

Commit

Permalink
Don’t attempt to copy built-in modules
Browse files Browse the repository at this point in the history
Several distributions (including Ubuntu) ship some of the modules we
rely on compiled into the kernel. Since these modules are listed in
modules.builtin, it’s very easy to detect and skip them.

This change fixes #13 and supersedes #36.

Signed-off-by: Andrej Shadura <[email protected]>
  • Loading branch information
andrewshadura authored and sjoerdsimons committed May 27, 2020
1 parent ff4e060 commit f9b6c06
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package fakemachine

import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -357,7 +358,30 @@ func (m *Machine) writerKernelModules(w *writerhelper.WriterHelper) error {
moddir = "/usr/lib/modules"
}

// build a list of built-in modules so that we don’t attempt to copy them
var builtinModules = make(map[string]bool)

f, err := os.Open(path.Join(moddir, kernelRelease, "modules.builtin"))
if err != nil {
return err
}
defer f.Close()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
module := scanner.Text()
builtinModules[module] = true
}

if err := scanner.Err(); err != nil {
return err
}

for _, v := range modules {
if builtinModules[v] {
continue
}

modpath := path.Join(moddir, kernelRelease, v)

if strings.HasSuffix(modpath, ".ko") {
Expand Down

0 comments on commit f9b6c06

Please sign in to comment.