[Libguestfs] [PATCH 1/2] inspection: Set package manager to "unknown" if parsing major version failed (RHBZ#1332025).

Richard W.M. Jones rjones at redhat.com
Wed May 4 13:12:29 UTC 2016


In cases where parsing the release file failed and so we have an
obviously incorrect major version number, don't try to infer the
package manager from the major version number.

In the bug report, parsing the /etc/redhat-release file of a CentOS
7.1 guest failed, so major version was set to 0, and the package
manager was inferred as "up2date".  virt-customize then failed with a
peculiar error:

  virt-customize: sorry, don't know how to use --install with the 'up2date' package manager

Instead this sets it to "unknown" which will cause virt-customize to
fail with:

  virt-customize: --install is not supported for this guest operating system

which is (only very slightly) better.

Problem reported by novegin on IRC.
---
 src/inspect-fs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 0714ae1..7f7d5d1 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -531,8 +531,11 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
         guestfs_is_file_opts (g, "/usr/bin/dnf",
                               GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0)
       fs->package_management = OS_PACKAGE_MANAGEMENT_DNF;
-    else
+    else if (fs->major_version >= 1)
       fs->package_management = OS_PACKAGE_MANAGEMENT_YUM;
+    else
+      /* Probably parsing the release file failed, see RHBZ#1332025. */
+      fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN;
     break;
 
   case OS_DISTRO_REDHAT_BASED:
@@ -542,8 +545,11 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
   case OS_DISTRO_ORACLE_LINUX:
     if (fs->major_version >= 5)
       fs->package_management = OS_PACKAGE_MANAGEMENT_YUM;
-    else
+    else if (fs->major_version >= 2)
       fs->package_management = OS_PACKAGE_MANAGEMENT_UP2DATE;
+    else
+      /* Probably parsing the release file failed, see RHBZ#1332025. */
+      fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN;
     break;
 
   case OS_DISTRO_DEBIAN:
-- 
2.7.4




More information about the Libguestfs mailing list