mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 10:35:20 +00:00
libxl: convert over to use GRegex for regular expressions
Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
16121a88a7
commit
9c999bf804
@ -21,7 +21,6 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <libxl.h>
|
#include <libxl.h>
|
||||||
#include <regex.h>
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
@ -374,10 +373,10 @@ static int
|
|||||||
libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
||||||
{
|
{
|
||||||
const libxl_version_info *ver_info;
|
const libxl_version_info *ver_info;
|
||||||
int err;
|
g_autoptr(GRegex) regex = NULL;
|
||||||
regex_t regex;
|
g_autoptr(GError) err = NULL;
|
||||||
|
g_autoptr(GMatchInfo) info = NULL;
|
||||||
char *str, *token;
|
char *str, *token;
|
||||||
regmatch_t subs[4];
|
|
||||||
char *saveptr = NULL;
|
char *saveptr = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -398,12 +397,10 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = regcomp(®ex, XEN_CAP_REGEX, REG_EXTENDED);
|
regex = g_regex_new(XEN_CAP_REGEX, G_REGEX_EXTENDED, 0, &err);
|
||||||
if (err != 0) {
|
if (!regex) {
|
||||||
char error[100];
|
|
||||||
regerror(err, ®ex, error, sizeof(error));
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to compile regex %s"), error);
|
_("Failed to compile regex %s"), err->message);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,31 +433,31 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
|||||||
nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0])
|
nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0])
|
||||||
&& (token = strtok_r(str, " ", &saveptr)) != NULL;
|
&& (token = strtok_r(str, " ", &saveptr)) != NULL;
|
||||||
str = NULL) {
|
str = NULL) {
|
||||||
if (regexec(®ex, token, sizeof(subs) / sizeof(subs[0]),
|
if (g_regex_match(regex, token, 0, &info)) {
|
||||||
subs, 0) == 0) {
|
g_autofree char *modestr = g_match_info_fetch(info, 1);
|
||||||
int hvm = STRPREFIX(&token[subs[1].rm_so], "hvm");
|
g_autofree char *archstr = g_match_info_fetch(info, 2);
|
||||||
|
g_autofree char *suffixstr = g_match_info_fetch(info, 3);
|
||||||
|
int hvm = STRPREFIX(modestr, "hvm");
|
||||||
virArch arch;
|
virArch arch;
|
||||||
int pae = 0, nonpae = 0, ia64_be = 0;
|
int pae = 0, nonpae = 0, ia64_be = 0;
|
||||||
|
|
||||||
if (STRPREFIX(&token[subs[2].rm_so], "x86_32")) {
|
if (STRPREFIX(archstr, "x86_32")) {
|
||||||
arch = VIR_ARCH_I686;
|
arch = VIR_ARCH_I686;
|
||||||
if (subs[3].rm_so != -1 &&
|
if (suffixstr != NULL && STRPREFIX(suffixstr, "p"))
|
||||||
STRPREFIX(&token[subs[3].rm_so], "p"))
|
|
||||||
pae = 1;
|
pae = 1;
|
||||||
else
|
else
|
||||||
nonpae = 1;
|
nonpae = 1;
|
||||||
} else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) {
|
} else if (STRPREFIX(archstr, "x86_64")) {
|
||||||
arch = VIR_ARCH_X86_64;
|
arch = VIR_ARCH_X86_64;
|
||||||
} else if (STRPREFIX(&token[subs[2].rm_so], "ia64")) {
|
} else if (STRPREFIX(archstr, "ia64")) {
|
||||||
arch = VIR_ARCH_ITANIUM;
|
arch = VIR_ARCH_ITANIUM;
|
||||||
if (subs[3].rm_so != -1 &&
|
if (suffixstr != NULL && STRPREFIX(suffixstr, "be"))
|
||||||
STRPREFIX(&token[subs[3].rm_so], "be"))
|
|
||||||
ia64_be = 1;
|
ia64_be = 1;
|
||||||
} else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) {
|
} else if (STRPREFIX(archstr, "powerpc64")) {
|
||||||
arch = VIR_ARCH_PPC64;
|
arch = VIR_ARCH_PPC64;
|
||||||
} else if (STRPREFIX(&token[subs[2].rm_so], "armv7l")) {
|
} else if (STRPREFIX(archstr, "armv7l")) {
|
||||||
arch = VIR_ARCH_ARMV7L;
|
arch = VIR_ARCH_ARMV7L;
|
||||||
} else if (STRPREFIX(&token[subs[2].rm_so], "aarch64")) {
|
} else if (STRPREFIX(archstr, "aarch64")) {
|
||||||
arch = VIR_ARCH_AARCH64;
|
arch = VIR_ARCH_AARCH64;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@ -515,7 +512,6 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
regfree(®ex);
|
|
||||||
|
|
||||||
for (i = 0; i < nr_guest_archs; ++i) {
|
for (i = 0; i < nr_guest_archs; ++i) {
|
||||||
virCapsGuestPtr guest;
|
virCapsGuestPtr guest;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user