Sophie

Sophie

distrib > Mandriva > current > i586 > media > contrib-release-src > by-pkgid > e29f98db7cfa7b73381a9ffacd2c0b49 > files > 4

ocsinventory-agent-1.1.2-4mdv2010.1.src.rpm

diff -Naur -x '*~' Ocsinventory-Agent-1.1.2/lib/Ocsinventory/Agent/Backend/Virtualization/Vmsystem.pm Ocsinventory-Agent-1.1.2-fix-xen-dom0-identification/lib/Ocsinventory/Agent/Backend/Virtualization/Vmsystem.pm
--- Ocsinventory-Agent-1.1.2/lib/Ocsinventory/Agent/Backend/Virtualization/Vmsystem.pm	2010-01-03 16:04:59.000000000 +0100
+++ Ocsinventory-Agent-1.1.2-fix-xen-dom0-identification/lib/Ocsinventory/Agent/Backend/Virtualization/Vmsystem.pm	2010-05-27 14:26:13.253368333 +0200
@@ -77,17 +77,19 @@
         $found = 1;
     }
  
-    # paravirtualized oldstyle Xen - very simple ;)
-    if(-d '/proc/xen') {
-        $status = "Xen";
+    if (
+        -d '/proc/xen' || 
+        check_file_content(
+          '/sys/devices/system/clocksource/clocksource0/available_clocksource',
+          'xen'
+        )
+    ) {
         $found = 1 ;
-    }
-
-    # newstyle Xen
-    if($found == 0 and -r '/sys/devices/system/clocksource/clocksource0/available_clocksource') {
-        if(`cat /sys/devices/system/clocksource/clocksource0/available_clocksource` =~ /xen/) {
+        if (check_file_content('/proc/xen/capabilities', 'control_d')) {
+          # dom0 host
+        } else {
+          # domU PV host
           $status = "Xen";
-          $found = 1 ;
         }
     }
 
@@ -209,4 +211,22 @@
       });
 }
 
+sub check_file_content {
+    my ($file, $pattern) = @_;
+
+    return 0 unless -r $file;
+
+    my $found = 0;
+    open (my $fh, '<', $file) or die "Can't open file $file: $!";
+    while (my $line = <$fh>) {
+        if ($line =~ /$pattern/) {
+            $found = 1;
+            last;
+        }
+    }
+    close ($fh);
+
+    return $found;
+}
+
 1;