-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathload.go
41 lines (34 loc) · 783 Bytes
/
load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package modprobe
import (
"os"
"golang.org/x/sys/unix"
)
// Load will, given a short module name (such as `g_ether`), determine where
// the kernel module is located, determine any dependencies, and load all
// required modules.
func Load(module, params string) error {
path, err := ResolveName(module)
if err != nil {
return err
}
order, err := Dependencies(path)
if err != nil {
return err
}
paramList := make([]string, len(order))
paramList[len(order)-1] = params
for i, module := range order {
fd, err := os.Open(module)
if err != nil {
return err
}
/* not doing a defer since we're in a loop */
param := paramList[i]
if err := Init(fd, param); err != nil && err != unix.EEXIST {
fd.Close()
return err
}
fd.Close()
}
return nil
}