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 committed Feb 28, 2020
1 parent 4a4d9a1 commit ccd122f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 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 @@ -352,10 +353,33 @@ func (m *Machine) writerKernelModules(w *writerhelper.WriterHelper) error {
"modules.builtin.bin",
"modules.devname"}

usrpath := "/lib/modules"
if mergedUsrSystem() {
usrpath = "/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(usrpath, 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 {
usrpath := "/lib/modules"
if mergedUsrSystem() {
usrpath = "/usr/lib/modules"
if builtinModules[v] {
continue
}
if err := w.CopyFile(path.Join(usrpath, kernelRelease, v)); err != nil {
return err
Expand Down

0 comments on commit ccd122f

Please sign in to comment.