Nikos Skalkotos
2014-May-05 14:24 UTC
[Libguestfs] [PATCH] inspect: Add support for Oracle Linux
Prior to this patch the library would return "rhel" instead of "oraclelinux" for Oracle Linux OSes. --- generator/actions.ml | 4 ++++ src/guestfs-internal.h | 1 + src/inspect-fs-cd.c | 25 +++++++++++++++++++++++++ src/inspect-fs-unix.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/inspect-fs.c | 2 ++ src/inspect-icon.c | 1 + src/inspect.c | 1 + 7 files changed, 78 insertions(+), 1 deletion(-) diff --git a/generator/actions.ml b/generator/actions.ml index ef3f17e..72846fd 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -1077,6 +1077,10 @@ OpenBSD. OpenSUSE. +=item \"oraclelinux\" + +Oracle Linux. + =item \"pardus\" Pardus. diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 63065c4..b99335b 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -540,6 +540,7 @@ enum inspect_os_distro { OS_DISTRO_SUSE_BASED, OS_DISTRO_SLES, OS_DISTRO_OPENBSD, + OS_DISTRO_ORACLE_LINUX, }; enum inspect_os_package_format { diff --git a/src/inspect-fs-cd.c b/src/inspect-fs-cd.c index 45d7bb5..8e1e8d0 100644 --- a/src/inspect-fs-cd.c +++ b/src/inspect-fs-cd.c @@ -211,6 +211,16 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs) free (str); } + r = guestfs___first_egrep_of_file (g, "/.treeinfo", + "^family = Oracle Linux Server$", + 0, &str); + if (r == -1) + return -1; + if (r > 0) { + fs->distro = OS_DISTRO_ORACLE_LINUX; + free (str); + } + /* XXX should do major.minor before this */ r = guestfs___first_egrep_of_file (g, "/.treeinfo", "^version = [[:digit:]]+", 0, &str); @@ -324,6 +334,21 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs) return -1; } + /* XXX parse major.minor */ + r = guestfs___first_egrep_of_file (g, "/isolinux/isolinux.cfg", + "^menu title Welcome to Oracle Linux Server [[:digit:]]+", + 0, &str); + if (r == -1) + return -1; + if (r > 0) { + fs->distro = OS_DISTRO_ORACLE_LINUX; + fs->major_version + guestfs___parse_unsigned_int_ignore_trailing (g, &str[42]); + free (str); + if (fs->major_version == -1) + return -1; + } + return 0; } diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index 17b0b5f..739a431 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -60,6 +60,9 @@ static pcre *re_centos_no_minor; static pcre *re_scientific_linux_old; static pcre *re_scientific_linux; static pcre *re_scientific_linux_no_minor; +static pcre *re_oracle_linux_old; +static pcre *re_oracle_linux; +static pcre *re_oracle_linux_no_minor; static pcre *re_major_minor; static pcre *re_xdev; static pcre *re_cciss; @@ -112,6 +115,12 @@ compile_regexps (void) "Scientific Linux.*release (\\d+)\\.(\\d+)", 0); COMPILE (re_scientific_linux_no_minor, "Scientific Linux.*release (\\d+)", 0); + COMPILE (re_oracle_linux_old, + "Oracle Linux.*release (\\d+).*Update (\\d+)", 0); + COMPILE (re_oracle_linux, + "Oracle Linux.*release (\\d+)\\.(\\d+)", 0); + COMPILE (re_oracle_linux_no_minor, + "Oracle Linux.*release (\\d+)", 0); COMPILE (re_major_minor, "(\\d+)\\.(\\d+)", 0); COMPILE (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0); COMPILE (re_cciss, "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$", 0); @@ -141,6 +150,9 @@ free_regexps (void) pcre_free (re_scientific_linux_old); pcre_free (re_scientific_linux); pcre_free (re_scientific_linux_no_minor); + pcre_free (re_oracle_linux_old); + pcre_free (re_oracle_linux); + pcre_free (re_oracle_linux_no_minor); pcre_free (re_major_minor); pcre_free (re_xdev); pcre_free (re_cciss); @@ -417,8 +429,39 @@ guestfs___check_linux_root (guestfs_h *g, struct inspect_fs *fs) goto skip_release_checks; } - if (guestfs_is_file_opts (g, "/etc/redhat-release", + /* Oracle Linux includes a "/etc/redhat-release" file, hence the Oracle check + * needs 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) { + + fs->distro = OS_DISTRO_ORACLE_LINUX; + + if (parse_release_file (g, fs, "/etc/oracle-release") == -1) + return -1; + + if (match2 (g, fs->product_name, re_oracle_linux_old, &major, &minor) || + match2 (g, fs->product_name, re_oracle_linux, &major, &minor)) { + fs->major_version = guestfs___parse_unsigned_int (g, major); + free (major); + if (fs->major_version == -1) { + free (minor); + return -1; + } + fs->minor_version = guestfs___parse_unsigned_int (g, minor); + free (minor); + if (fs->minor_version == -1) + return -1; + } else if ((major = match1 (g, fs->product_name, re_oracle_linux_no_minor)) != NULL) { + fs->major_version = guestfs___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. */ if (parse_release_file (g, fs, "/etc/redhat-release") == -1) diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 89c9335..c011b5a 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -449,6 +449,7 @@ guestfs___check_package_format (guestfs_h *g, struct inspect_fs *fs) case OS_DISTRO_SLES: case OS_DISTRO_CENTOS: case OS_DISTRO_SCIENTIFIC_LINUX: + case OS_DISTRO_ORACLE_LINUX: fs->package_format = OS_PACKAGE_FORMAT_RPM; break; @@ -494,6 +495,7 @@ guestfs___check_package_management (guestfs_h *g, struct inspect_fs *fs) case OS_DISTRO_RHEL: case OS_DISTRO_CENTOS: case OS_DISTRO_SCIENTIFIC_LINUX: + case OS_DISTRO_ORACLE_LINUX: if (fs->major_version >= 5) fs->package_management = OS_PACKAGE_MANAGEMENT_YUM; else diff --git a/src/inspect-icon.c b/src/inspect-icon.c index f4194f5..94b63a2 100644 --- a/src/inspect-icon.c +++ b/src/inspect-icon.c @@ -137,6 +137,7 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r, case OS_DISTRO_REDHAT_BASED: case OS_DISTRO_CENTOS: case OS_DISTRO_SCIENTIFIC_LINUX: + case OS_DISTRO_ORACLE_LINUX: r = icon_rhel (g, fs, &size); break; diff --git a/src/inspect.c b/src/inspect.c index 49bf765..1a9554e 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -164,6 +164,7 @@ guestfs__inspect_get_distro (guestfs_h *g, const char *root) case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break; case OS_DISTRO_OPENBSD: ret = safe_strdup (g, "openbsd"); break; case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break; + case OS_DISTRO_ORACLE_LINUX: ret = safe_strdup (g, "oraclelinux"); break; case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break; case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break; case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break; -- 1.8.3.2
Richard W.M. Jones
2014-May-07 09:02 UTC
Re: [Libguestfs] [PATCH] inspect: Add support for Oracle Linux
On Mon, May 05, 2014 at 05:24:04PM +0300, Nikos Skalkotos wrote:> Prior to this patch the library would return "rhel" instead of > "oraclelinux" for Oracle Linux OSes.Thanks for the patch. I will push it shortly. Rich.> generator/actions.ml | 4 ++++ > src/guestfs-internal.h | 1 + > src/inspect-fs-cd.c | 25 +++++++++++++++++++++++++ > src/inspect-fs-unix.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- > src/inspect-fs.c | 2 ++ > src/inspect-icon.c | 1 + > src/inspect.c | 1 + > 7 files changed, 78 insertions(+), 1 deletion(-) > > diff --git a/generator/actions.ml b/generator/actions.ml > index ef3f17e..72846fd 100644 > --- a/generator/actions.ml > +++ b/generator/actions.ml > @@ -1077,6 +1077,10 @@ OpenBSD. > > OpenSUSE. > > +=item \"oraclelinux\" > + > +Oracle Linux. > + > =item \"pardus\" > > Pardus. > diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h > index 63065c4..b99335b 100644 > --- a/src/guestfs-internal.h > +++ b/src/guestfs-internal.h > @@ -540,6 +540,7 @@ enum inspect_os_distro { > OS_DISTRO_SUSE_BASED, > OS_DISTRO_SLES, > OS_DISTRO_OPENBSD, > + OS_DISTRO_ORACLE_LINUX, > }; > > enum inspect_os_package_format { > diff --git a/src/inspect-fs-cd.c b/src/inspect-fs-cd.c > index 45d7bb5..8e1e8d0 100644 > --- a/src/inspect-fs-cd.c > +++ b/src/inspect-fs-cd.c > @@ -211,6 +211,16 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs) > free (str); > } > > + r = guestfs___first_egrep_of_file (g, "/.treeinfo", > + "^family = Oracle Linux Server$", > + 0, &str); > + if (r == -1) > + return -1; > + if (r > 0) { > + fs->distro = OS_DISTRO_ORACLE_LINUX; > + free (str); > + } > + > /* XXX should do major.minor before this */ > r = guestfs___first_egrep_of_file (g, "/.treeinfo", > "^version = [[:digit:]]+", 0, &str); > @@ -324,6 +334,21 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs) > return -1; > } > > + /* XXX parse major.minor */ > + r = guestfs___first_egrep_of_file (g, "/isolinux/isolinux.cfg", > + "^menu title Welcome to Oracle Linux Server [[:digit:]]+", > + 0, &str); > + if (r == -1) > + return -1; > + if (r > 0) { > + fs->distro = OS_DISTRO_ORACLE_LINUX; > + fs->major_version > + guestfs___parse_unsigned_int_ignore_trailing (g, &str[42]); > + free (str); > + if (fs->major_version == -1) > + return -1; > + } > + > return 0; > } > > diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c > index 17b0b5f..739a431 100644 > --- a/src/inspect-fs-unix.c > +++ b/src/inspect-fs-unix.c > @@ -60,6 +60,9 @@ static pcre *re_centos_no_minor; > static pcre *re_scientific_linux_old; > static pcre *re_scientific_linux; > static pcre *re_scientific_linux_no_minor; > +static pcre *re_oracle_linux_old; > +static pcre *re_oracle_linux; > +static pcre *re_oracle_linux_no_minor; > static pcre *re_major_minor; > static pcre *re_xdev; > static pcre *re_cciss; > @@ -112,6 +115,12 @@ compile_regexps (void) > "Scientific Linux.*release (\\d+)\\.(\\d+)", 0); > COMPILE (re_scientific_linux_no_minor, > "Scientific Linux.*release (\\d+)", 0); > + COMPILE (re_oracle_linux_old, > + "Oracle Linux.*release (\\d+).*Update (\\d+)", 0); > + COMPILE (re_oracle_linux, > + "Oracle Linux.*release (\\d+)\\.(\\d+)", 0); > + COMPILE (re_oracle_linux_no_minor, > + "Oracle Linux.*release (\\d+)", 0); > COMPILE (re_major_minor, "(\\d+)\\.(\\d+)", 0); > COMPILE (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0); > COMPILE (re_cciss, "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$", 0); > @@ -141,6 +150,9 @@ free_regexps (void) > pcre_free (re_scientific_linux_old); > pcre_free (re_scientific_linux); > pcre_free (re_scientific_linux_no_minor); > + pcre_free (re_oracle_linux_old); > + pcre_free (re_oracle_linux); > + pcre_free (re_oracle_linux_no_minor); > pcre_free (re_major_minor); > pcre_free (re_xdev); > pcre_free (re_cciss); > @@ -417,8 +429,39 @@ guestfs___check_linux_root (guestfs_h *g, struct inspect_fs *fs) > goto skip_release_checks; > } > > - if (guestfs_is_file_opts (g, "/etc/redhat-release", > + /* Oracle Linux includes a "/etc/redhat-release" file, hence the Oracle check > + * needs 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) { > + > + fs->distro = OS_DISTRO_ORACLE_LINUX; > + > + if (parse_release_file (g, fs, "/etc/oracle-release") == -1) > + return -1; > + > + if (match2 (g, fs->product_name, re_oracle_linux_old, &major, &minor) || > + match2 (g, fs->product_name, re_oracle_linux, &major, &minor)) { > + fs->major_version = guestfs___parse_unsigned_int (g, major); > + free (major); > + if (fs->major_version == -1) { > + free (minor); > + return -1; > + } > + fs->minor_version = guestfs___parse_unsigned_int (g, minor); > + free (minor); > + if (fs->minor_version == -1) > + return -1; > + } else if ((major = match1 (g, fs->product_name, re_oracle_linux_no_minor)) != NULL) { > + fs->major_version = guestfs___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. */ > > if (parse_release_file (g, fs, "/etc/redhat-release") == -1) > diff --git a/src/inspect-fs.c b/src/inspect-fs.c > index 89c9335..c011b5a 100644 > --- a/src/inspect-fs.c > +++ b/src/inspect-fs.c > @@ -449,6 +449,7 @@ guestfs___check_package_format (guestfs_h *g, struct inspect_fs *fs) > case OS_DISTRO_SLES: > case OS_DISTRO_CENTOS: > case OS_DISTRO_SCIENTIFIC_LINUX: > + case OS_DISTRO_ORACLE_LINUX: > fs->package_format = OS_PACKAGE_FORMAT_RPM; > break; > > @@ -494,6 +495,7 @@ guestfs___check_package_management (guestfs_h *g, struct inspect_fs *fs) > case OS_DISTRO_RHEL: > case OS_DISTRO_CENTOS: > case OS_DISTRO_SCIENTIFIC_LINUX: > + case OS_DISTRO_ORACLE_LINUX: > if (fs->major_version >= 5) > fs->package_management = OS_PACKAGE_MANAGEMENT_YUM; > else > diff --git a/src/inspect-icon.c b/src/inspect-icon.c > index f4194f5..94b63a2 100644 > --- a/src/inspect-icon.c > +++ b/src/inspect-icon.c > @@ -137,6 +137,7 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r, > case OS_DISTRO_REDHAT_BASED: > case OS_DISTRO_CENTOS: > case OS_DISTRO_SCIENTIFIC_LINUX: > + case OS_DISTRO_ORACLE_LINUX: > r = icon_rhel (g, fs, &size); > break; > > diff --git a/src/inspect.c b/src/inspect.c > index 49bf765..1a9554e 100644 > --- a/src/inspect.c > +++ b/src/inspect.c > @@ -164,6 +164,7 @@ guestfs__inspect_get_distro (guestfs_h *g, const char *root) > case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break; > case OS_DISTRO_OPENBSD: ret = safe_strdup (g, "openbsd"); break; > case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break; > + case OS_DISTRO_ORACLE_LINUX: ret = safe_strdup (g, "oraclelinux"); break; > case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break; > case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break; > case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break; > -- > 1.8.3.2 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html