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 go-debos#13 and supersedes go-debos#36.

Signed-off-by: Andrej Shadura <[email protected]>
  • Loading branch information
andrewshadura committed Feb 28, 2020
1 parent 7ca0095 commit db808ac
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 db808ac

Please sign in to comment.