-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathkmod.rb
51 lines (40 loc) · 1.37 KB
/
kmod.rb
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
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
# @summary Return a hash of loaded kernel modules
Facter.add(:kmods) do
confine kernel: :linux
kmod = {}
setcode do
if File.exist?('/sys/module')
Dir.foreach('/sys/module') do |directory|
next if ['.', '..'].include?(directory)
kmod[directory] = {
'parameters' => {},
'used_by' => [],
}
if File.directory?("/sys/module/#{directory}/parameters")
Dir.foreach("/sys/module/#{directory}/parameters") do |param|
next if ['.', '..'].include?(param)
next unless File.readable?("/sys/module/#{directory}/parameters/#{param}")
begin
kmod[directory]['parameters'][param] = File.read("/sys/module/#{directory}/parameters/#{param}").chomp
rescue StandardError
# some kernel parameters are write only
# even though they have the read bit set
# so just ignore read errors
nil
end
end
end
if File.directory?("/sys/module/#{directory}/holders")
Dir.foreach("/sys/module/#{directory}/holders") do |used|
next if ['.', '..'].include?(used)
kmod[directory]['used_by'] << used
end
end
end
kmod
else
Facter.debug('/sys/module is not found. skipping.')
end
end
end