inspection: Return root devices sorted.
[libguestfs.git] / src / inspect_fs_unix.c
index 2ea29ad..72b5666 100644 (file)
@@ -543,11 +543,18 @@ check_hostname_redhat (guestfs_h *g, struct inspect_fs *fs)
 {
   char *hostname;
 
+  /* Errors here are not fatal (RHBZ#726739), since it could be
+   * just missing HOSTNAME field in the file.
+   */
+  guestfs_error_handler_cb old_error_cb = g->error_cb;
+  g->error_cb = NULL;
   hostname = guestfs_aug_get (g, "/files/etc/sysconfig/network/HOSTNAME");
-  if (!hostname)
-    return -1;
+  g->error_cb = old_error_cb;
 
-  fs->hostname = hostname;  /* freed by guestfs___free_inspect_info */
+  /* This is freed by guestfs___free_inspect_info.  Note that hostname
+   * could be NULL because we ignored errors above.
+   */
+  fs->hostname = hostname;
   return 0;
 }
 
@@ -687,6 +694,9 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
   else if (STRPREFIX (spec, "LABEL="))
     device = guestfs_findfs_label (g, &spec[6]);
   /* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
+  else if (STREQ (spec, "/dev/root"))
+    /* Resolve /dev/root to the current device. */
+    device = safe_strdup (g, fs->device);
   else if (STRPREFIX (spec, "/dev/"))
     /* Resolve guest block device names. */
     device = resolve_fstab_device (g, spec);
@@ -785,15 +795,13 @@ resolve_fstab_device (guestfs_h *g, const char *spec)
     free (bsdslice);
     free (bsdpart);
 
-    if (disk == -1 || disk > 26 ||
-        slice <= 0 || slice > 1 /* > 4 .. see comment above */ ||
-        part < 0 || part >= 26)
-      goto out;
-
-    device = safe_asprintf (g, "/dev/sd%c%d", disk + 'a', part + 5);
+    if (disk != -1 && disk <= 26 &&
+        slice > 0 && slice <= 1 /* > 4 .. see comment above */ &&
+        part >= 0 && part < 26) {
+      device = safe_asprintf (g, "/dev/sd%c%d", disk + 'a', part + 5);
+    }
   }
 
- out:
   /* Didn't match device pattern, return original spec unchanged. */
   if (device == NULL)
     device = safe_strdup (g, spec);