Blame SOURCES/0009-virt-what.in-verify-files-exists-before-grepping-the.patch

b6cf65
From a68e9c005933a2d8d0f3264bdb68161263cd3933 Mon Sep 17 00:00:00 2001
b6cf65
From: Assaf Gordon <assafgordon@gmail.com>
b6cf65
Date: Mon, 15 Sep 2014 19:15:19 +0000
b6cf65
Subject: [PATCH 09/16] virt-what.in: verify files exists before grepping them
b6cf65
b6cf65
Don't grep linux-specific files (e.g. /proc/cpuinfo) unless they exist.
b6cf65
This avoids extraneous errors on BSD/Hurd systems which don't have these
b6cf65
files.
b6cf65
---
b6cf65
 virt-what.in | 14 ++++++++++----
b6cf65
 1 file changed, 10 insertions(+), 4 deletions(-)
b6cf65
b6cf65
diff --git a/virt-what.in b/virt-what.in
b6cf65
index 5ae1ccb..6e9aef1 100644
b6cf65
--- a/virt-what.in
b6cf65
+++ b/virt-what.in
b6cf65
@@ -33,6 +33,10 @@ skip_qemu_kvm=false
b6cf65
 
b6cf65
 VERSION="@VERSION@"
b6cf65
 
b6cf65
+have_cpuinfo() {
b6cf65
+    test -e "${root}/proc/cpuinfo"
b6cf65
+}
b6cf65
+
b6cf65
 fail() {
b6cf65
     echo "virt-what: $1" >&2
b6cf65
     exit 1
b6cf65
@@ -152,7 +156,8 @@ if [ -e "${root}/proc/1/environ" ] &&
b6cf65
 fi
b6cf65
 
b6cf65
 # Check for Linux-VServer
b6cf65
-if cat "${root}/proc/self/status" | grep -q "VxID: [0-9]*"; then
b6cf65
+if test -e "${root}/proc/self/status" \
b6cf65
+   && cat "${root}/proc/self/status" | grep -q "VxID: [0-9]*"; then
b6cf65
     echo linux_vserver
b6cf65
     if grep -q "VxID: 0$" "${root}/proc/self/status"; then
b6cf65
         echo linux_vserver-host
b6cf65
@@ -163,12 +168,13 @@ fi
b6cf65
 
b6cf65
 # Check for UML.
b6cf65
 # Added by Laurent LĂ©onard.
b6cf65
-if grep -q 'UML' "${root}/proc/cpuinfo"; then
b6cf65
+if have_cpuinfo && grep -q 'UML' "${root}/proc/cpuinfo"; then
b6cf65
     echo uml
b6cf65
 fi
b6cf65
 
b6cf65
 # Check for IBM PowerVM Lx86 Linux/x86 emulator.
b6cf65
-if grep -q '^vendor_id.*PowerVM Lx86' "${root}/proc/cpuinfo"; then
b6cf65
+if have_cpuinfo && grep -q '^vendor_id.*PowerVM Lx86' "${root}/proc/cpuinfo"
b6cf65
+then
b6cf65
     echo powervm_lx86
b6cf65
 fi
b6cf65
 
b6cf65
@@ -179,7 +185,7 @@ if echo "$dmi" | grep -q 'Manufacturer.*HITACHI' &&
b6cf65
 fi
b6cf65
 
b6cf65
 # Check for IBM SystemZ.
b6cf65
-if grep -q '^vendor_id.*IBM/S390' "${root}/proc/cpuinfo"; then
b6cf65
+if have_cpuinfo && grep -q '^vendor_id.*IBM/S390' "${root}/proc/cpuinfo"; then
b6cf65
     echo ibm_systemz
b6cf65
     if [ -f "${root}/proc/sysinfo" ]; then
b6cf65
         if grep -q 'VM.*Control Program.*z/VM' "${root}/proc/sysinfo"; then
b6cf65
-- 
b6cf65
2.3.1
b6cf65