0001-simplify-openvz-and-vserver-detection.patch

Benedikt Böhm, 04/10/2009 03:56 pm

Download (2.1 kB)

b/lib/facter/virtual.rb
4 4
    result = "physical"
5 5

  
6 6
    setcode do
7
        if FileTest.exists?("/proc/user_beancounters")
8
            # openvz. can be hardware node or virtual environment
9
            # read the init process' status file, it has laxer permissions
10
            # than /proc/user_beancounters (so this won't fail as non-root)
11
            txt = File.read("/proc/1/status")
12
            if txt =~ /^envID:[[:blank:]]+0$/mi
7
        if FileTest.exists?("/proc/vz/veinfo")
8
            if FileTest.exists?("/proc/vz/version")
13 9
                result = "openvzhn"
14 10
            else
15 11
                result = "openvzve"
16 12
            end
17 13
        end
18 14

  
15
        if FileTest.exists?("/proc/self/status")
16
            txt = File.read("/proc/self/status")
17
            if txt =~ /^(s_context|VxID):[[:blank:]]*[1-9]/
18
                result = "vserver"
19
            end
20
        end
21

  
22
        if FileTest.exists?("/proc/virtual")
23
            result = "vserver_host"
24
        end
25

  
19 26
        if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
20 27
            txt = File.read("/proc/xen/capabilities")
21 28
            if txt =~ /control_d/i
......
58 65
            result = "vmware_server"
59 66
        end
60 67

  
61
        mountexists = system "which mount > /dev/null 2>&1"
62
        if $?.exitstatus == 0
63
            output = %x{mount}
64
            output.each do |p|
65
                result = "vserver" if p =~ /\/dev\/hdv1/
66
            end
67
        end
68

  
69
        if FileTest.directory?('/proc/virtual')
70
            result = "vserver_host"
71
        end
72

  
73 68
        result
74 69
    end
75 70
end
76
-