[Libguestfs] [PATCH 1/2] inspect: recognize the ALT Linux distribution

Pino Toscano
2015-08-25T15:40:51Z

Check its presence ahead of /etc/redhat-release, as the distro provides
it and thus previously it was recognized as "redhat-based".
---
 generator/actions.ml   |  4 ++++
 src/guestfs-internal.h |  1 +
 src/inspect-fs-unix.c  | 21 +++++++++++++++++++++
 src/inspect-fs.c       |  2 ++
 src/inspect-icon.c     |  1 +
 src/inspect.c          |  1 +
 6 files changed, 30 insertions(+)

diff --git a/generator/actions.ml b/generator/actions.ml
index 1c22f9f..13c8bc8 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1059,6 +1059,10 @@ Currently defined distros are:

 Alpine Linux.

+=item \"altlinux\"
+
+ALT Linux.
+
 =item \"archlinux\"

 Arch Linux.
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 0c8857c..6cf3dad 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -553,6 +553,7 @@ enum inspect_os_distro {
   OS_DISTRO_NETBSD,
   OS_DISTRO_COREOS,
   OS_DISTRO_ALPINE_LINUX,
+  OS_DISTRO_ALTLINUX,
 };

 enum inspect_os_package_format {
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index abfa527..abbae35 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -84,6 +84,7 @@ COMPILE_REGEXP (re_openbsd, "^OpenBSD
(\\d+|\\?)\\.(\\d+|\\?)", 0)
 COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
 COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
 COMPILE_REGEXP (re_netbsd_dev, "^/dev/(l|s)d([0-9])([a-z])$", 0)
+COMPILE_REGEXP (re_altlinux, "
(?:(\\d+)(?:\\.(\\d+)(?:[\\.\\d]+)?)?)\\s+\\((?:[^)]+)\\)$", 0)

 static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
 static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -414,6 +415,26 @@ guestfs_int_check_linux_root (guestfs_h *g, struct
inspect_fs *fs)
       fs->minor_version = 0;
     }
   }
+  else if (guestfs_is_file_opts (g, "/etc/altlinux-release",
+                                 GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1)
> 0) {
+    fs->distro = OS_DISTRO_ALTLINUX;
+
+    if (parse_release_file (g, fs, "/etc/altlinux-release") == -1)
+      return -1;
+
+    if (match2 (g, fs->product_name, re_altlinux, &major, &minor)) {
+      fs->major_version = guestfs_int_parse_unsigned_int (g, major);
+      free (major);
+      if (fs->major_version == -1) {
+        free (minor);
+        return -1;
+      }
+      fs->minor_version = guestfs_int_parse_unsigned_int (g, minor);
+      free (minor);
+      if (fs->minor_version == -1)
+        return -1;
+    }
+  }
   else if (guestfs_is_file_opts (g, "/etc/redhat-release",
                                  GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1)
> 0) {
     fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like.
*/
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index aa198ad..b239302 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -465,6 +465,7 @@ guestfs_int_check_package_format (guestfs_h *g, struct
inspect_fs *fs)
   case OS_DISTRO_CENTOS:
   case OS_DISTRO_SCIENTIFIC_LINUX:
   case OS_DISTRO_ORACLE_LINUX:
+  case OS_DISTRO_ALTLINUX:
     fs->package_format = OS_PACKAGE_FORMAT_RPM;
     break;

@@ -536,6 +537,7 @@ guestfs_int_check_package_management (guestfs_h *g, struct
inspect_fs *fs)
   case OS_DISTRO_DEBIAN:
   case OS_DISTRO_UBUNTU:
   case OS_DISTRO_LINUX_MINT:
+  case OS_DISTRO_ALTLINUX:
     fs->package_management = OS_PACKAGE_MANAGEMENT_APT;
     break;

diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index 77256a3..93cd67a 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -183,6 +183,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char
*root, size_t *size_r,
     case OS_DISTRO_NETBSD:
     case OS_DISTRO_OPENBSD:
     case OS_DISTRO_ALPINE_LINUX:
+    case OS_DISTRO_ALTLINUX:
     case OS_DISTRO_UNKNOWN:
       ; /* nothing */
     }
diff --git a/src/inspect.c b/src/inspect.c
index 9332fc4..c01888a 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -256,6 +256,7 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char
*root)

   switch (fs->distro) {
   case OS_DISTRO_ALPINE_LINUX: ret = safe_strdup (g, "alpinelinux");
break;
+  case OS_DISTRO_ALTLINUX: ret = safe_strdup (g, "altlinux"); break;
   case OS_DISTRO_ARCHLINUX: ret = safe_strdup (g, "archlinux");
break;
   case OS_DISTRO_BUILDROOT: ret = safe_strdup (g, "buildroot");
break;
   case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
--
2.1.0