inspect: Add support for Ubuntu.
authorRichard Jones <rjones@redhat.com>
Fri, 29 Oct 2010 10:54:34 +0000 (11:54 +0100)
committerRichard Jones <rjones@redhat.com>
Fri, 29 Oct 2010 10:54:54 +0000 (11:54 +0100)
configure.ac
generator/generator_actions.ml
inspector/virt-inspector
src/guestfs-internal.h
src/inspect.c

index f4a174c..1cb66a8 100644 (file)
@@ -129,6 +129,9 @@ if test "$gl_gcc_warnings" = yes; then
   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
   gl_WARN_ADD([-Wno-logical-op])
 
   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
   gl_WARN_ADD([-Wno-logical-op])
 
+  # Work around warning in src/inspect.c.  This seems to be a bug in gcc 4.5.1.
+  gl_WARN_ADD([-Wno-strict-overflow])
+
   gl_WARN_ADD([-fdiagnostics-show-option])
 
   AC_SUBST([WARN_CFLAGS])
   gl_WARN_ADD([-fdiagnostics-show-option])
 
   AC_SUBST([WARN_CFLAGS])
index 5aa5359..49053a3 100644 (file)
@@ -812,6 +812,10 @@ Red Hat Enterprise Linux and some derivatives.
 Windows does not have distributions.  This string is
 returned if the OS type is Windows.
 
 Windows does not have distributions.  This string is
 returned if the OS type is Windows.
 
+=item \"ubuntu\"
+
+Ubuntu.
+
 =item \"unknown\"
 
 The distro could not be determined.
 =item \"unknown\"
 
 The distro could not be determined.
index fbe05d8..04226b3 100755 (executable)
@@ -381,7 +381,7 @@ sub output_applications
             $package_format = "pacman";
             $package_management = "pacman";
         }
             $package_format = "pacman";
             $package_management = "pacman";
         }
-        elsif ($distro eq "debian") {
+        elsif ($distro eq "debian" || $distro eq "ubuntu") {
             $package_format = "deb";
             $package_management = "apt";
         }
             $package_format = "deb";
             $package_management = "apt";
         }
index 6a4a422..4f64e9a 100644 (file)
@@ -169,6 +169,7 @@ enum inspect_os_distro {
   OS_DISTRO_PARDUS,
   OS_DISTRO_ARCHLINUX,
   OS_DISTRO_GENTOO,
   OS_DISTRO_PARDUS,
   OS_DISTRO_ARCHLINUX,
   OS_DISTRO_GENTOO,
+  OS_DISTRO_UBUNTU,
 };
 
 struct inspect_fs {
 };
 
 struct inspect_fs {
index 6e22360..33da144 100644 (file)
@@ -666,6 +666,67 @@ parse_major_minor (guestfs_h *g, struct inspect_fs *fs)
   return 0;
 }
 
   return 0;
 }
 
+/* Ubuntu has /etc/lsb-release containing:
+ *   DISTRIB_ID=Ubuntu                                # Distro
+ *   DISTRIB_RELEASE=10.04                            # Version
+ *   DISTRIB_CODENAME=lucid
+ *   DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"         # Product name
+ * In theory other distros could have this LSB file, but none do.
+ */
+static int
+parse_lsb_release (guestfs_h *g, struct inspect_fs *fs)
+{
+  char **lines;
+  size_t i;
+  int r = 0;
+
+  lines = guestfs_head_n (g, 10, "/etc/lsb-release");
+  if (lines == NULL)
+    return -1;
+
+  for (i = 0; lines[i] != NULL; ++i) {
+    if (fs->distro == 0 &&
+        STREQ (lines[i], "DISTRIB_ID=Ubuntu")) {
+      fs->distro = OS_DISTRO_UBUNTU;
+      r = 1;
+    }
+    else if (STRPREFIX (lines[i], "DISTRIB_RELEASE=")) {
+      char *major, *minor;
+      if (match2 (g, &lines[i][16], re_major_minor, &major, &minor)) {
+        fs->major_version = parse_unsigned_int (g, major);
+        free (major);
+        if (fs->major_version == -1) {
+          free (minor);
+          free_string_list (lines);
+          return -1;
+        }
+        fs->minor_version = parse_unsigned_int (g, minor);
+        free (minor);
+        if (fs->minor_version == -1) {
+          free_string_list (lines);
+          return -1;
+        }
+      }
+    }
+    else if (fs->product_name == NULL &&
+             (STRPREFIX (lines[i], "DISTRIB_DESCRIPTION=\"") ||
+              STRPREFIX (lines[i], "DISTRIB_DESCRIPTION='"))) {
+      size_t len = strlen (lines[i]) - 21 - 1;
+      fs->product_name = safe_strndup (g, &lines[i][21], len);
+      r = 1;
+    }
+    else if (fs->product_name == NULL &&
+             STRPREFIX (lines[i], "DISTRIB_DESCRIPTION=")) {
+      size_t len = strlen (lines[i]) - 20;
+      fs->product_name = safe_strndup (g, &lines[i][20], len);
+      r = 1;
+    }
+  }
+
+  free_string_list (lines);
+  return r;
+}
+
 /* The currently mounted device is known to be a Linux root.  Try to
  * determine from this the distro, version, etc.  Also parse
  * /etc/fstab to determine the arrangement of mountpoints and
 /* The currently mounted device is known to be a Linux root.  Try to
  * determine from this the distro, version, etc.  Also parse
  * /etc/fstab to determine the arrangement of mountpoints and
@@ -674,8 +735,18 @@ parse_major_minor (guestfs_h *g, struct inspect_fs *fs)
 static int
 check_linux_root (guestfs_h *g, struct inspect_fs *fs)
 {
 static int
 check_linux_root (guestfs_h *g, struct inspect_fs *fs)
 {
+  int r;
+
   fs->type = OS_TYPE_LINUX;
 
   fs->type = OS_TYPE_LINUX;
 
+  if (guestfs_exists (g, "/etc/lsb-release") > 0) {
+    r = parse_lsb_release (g, fs);
+    if (r == -1)        /* error */
+      return -1;
+    if (r == 1)         /* ok - detected the release from this file */
+      goto skip_release_checks;
+  }
+
   if (guestfs_exists (g, "/etc/redhat-release") > 0) {
     fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
 
   if (guestfs_exists (g, "/etc/redhat-release") > 0) {
     fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
 
@@ -748,6 +819,8 @@ check_linux_root (guestfs_h *g, struct inspect_fs *fs)
       return -1;
   }
 
       return -1;
   }
 
+ skip_release_checks:;
+
   /* Determine the architecture. */
   const char *binaries[] =
     { "/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh" };
   /* Determine the architecture. */
   const char *binaries[] =
     { "/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh" };
@@ -783,7 +856,7 @@ check_linux_root (guestfs_h *g, struct inspect_fs *fs)
   guestfs_aug_rm (g, "/augeas/load//incl[. != \"/etc/fstab\"]");
   guestfs_aug_load (g);
 
   guestfs_aug_rm (g, "/augeas/load//incl[. != \"/etc/fstab\"]");
   guestfs_aug_load (g);
 
-  int r = check_fstab (g, fs);
+  r = check_fstab (g, fs);
   guestfs_aug_close (g);
   if (r == -1)
     return -1;
   guestfs_aug_close (g);
   if (r == -1)
     return -1;
@@ -1269,6 +1342,7 @@ guestfs__inspect_get_distro (guestfs_h *g, const char *root)
   case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
   case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
   case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
   case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
   case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
   case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
+  case OS_DISTRO_UBUNTU: ret = safe_strdup (g, "ubuntu"); break;
   case OS_DISTRO_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
   }
 
   case OS_DISTRO_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
   }