[Libguestfs] [PATCH] inspection: fix CentOS 7 detection
Richard W.M. Jones
rjones at redhat.com
Tue Jun 2 14:13:18 UTC 2015
On Fri, May 29, 2015 at 04:01:26PM +0200, Pino Toscano wrote:
> In newer CentOS 7 versions /etc/redhat-release says that the distro is
> derived from RHEL, so we need to look at /etc/centos-release for
> actually identifying it as CentOS.
>
> The old code is needed as sub-case of /etc/redhat-release, as on
> CentOS < 7 that file is a symlink to /etc/centos-release.
> ---
> src/inspect-fs-unix.c | 32 ++++++++++++++++++++++++++++++--
> 1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
> index 2abbf24..f0fe141 100644
> --- a/src/inspect-fs-unix.c
> +++ b/src/inspect-fs-unix.c
> @@ -345,8 +345,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
> goto skip_release_checks;
> }
>
> - /* Oracle Linux includes a "/etc/redhat-release" file, hence the Oracle check
> - * needs to be performed before the Red-Hat one.
> + /* RHEL-based distros include a "/etc/redhat-release" file, hence their
> + * checks need to be performed before the Red-Hat one.
> */
> if (guestfs_is_file_opts (g, "/etc/oracle-release",
> GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
> @@ -376,6 +376,34 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
> fs->minor_version = 0;
> }
> }
> + else if (guestfs_is_file_opts (g, "/etc/centos-release",
> + GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
> + fs->distro = OS_DISTRO_CENTOS;
> +
> + if (parse_release_file (g, fs, "/etc/centos-release") == -1)
> + return -1;
> +
> + if (match2 (g, fs->product_name, re_centos_old, &major, &minor) ||
> + match2 (g, fs->product_name, re_centos, &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 ((major = match1 (g, fs->product_name, re_centos_no_minor)) != NULL) {
> + fs->major_version = guestfs_int_parse_unsigned_int (g, major);
> + free (major);
> + if (fs->major_version == -1)
> + return -1;
> + fs->minor_version = 0;
> + }
> + }
> 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. */
> --
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the Libguestfs
mailing list