mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-03 15:43:51 +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 <libxl.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "virlog.h"
|
||||
@ -374,10 +373,10 @@ static int
|
||||
libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
||||
{
|
||||
const libxl_version_info *ver_info;
|
||||
int err;
|
||||
regex_t regex;
|
||||
g_autoptr(GRegex) regex = NULL;
|
||||
g_autoptr(GError) err = NULL;
|
||||
g_autoptr(GMatchInfo) info = NULL;
|
||||
char *str, *token;
|
||||
regmatch_t subs[4];
|
||||
char *saveptr = NULL;
|
||||
size_t i;
|
||||
|
||||
@ -398,12 +397,10 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = regcomp(®ex, XEN_CAP_REGEX, REG_EXTENDED);
|
||||
if (err != 0) {
|
||||
char error[100];
|
||||
regerror(err, ®ex, error, sizeof(error));
|
||||
regex = g_regex_new(XEN_CAP_REGEX, G_REGEX_EXTENDED, 0, &err);
|
||||
if (!regex) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to compile regex %s"), error);
|
||||
_("Failed to compile regex %s"), err->message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -436,31 +433,31 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
||||
nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0])
|
||||
&& (token = strtok_r(str, " ", &saveptr)) != NULL;
|
||||
str = NULL) {
|
||||
if (regexec(®ex, token, sizeof(subs) / sizeof(subs[0]),
|
||||
subs, 0) == 0) {
|
||||
int hvm = STRPREFIX(&token[subs[1].rm_so], "hvm");
|
||||
if (g_regex_match(regex, token, 0, &info)) {
|
||||
g_autofree char *modestr = g_match_info_fetch(info, 1);
|
||||
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;
|
||||
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;
|
||||
if (subs[3].rm_so != -1 &&
|
||||
STRPREFIX(&token[subs[3].rm_so], "p"))
|
||||
if (suffixstr != NULL && STRPREFIX(suffixstr, "p"))
|
||||
pae = 1;
|
||||
else
|
||||
nonpae = 1;
|
||||
} else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) {
|
||||
} else if (STRPREFIX(archstr, "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;
|
||||
if (subs[3].rm_so != -1 &&
|
||||
STRPREFIX(&token[subs[3].rm_so], "be"))
|
||||
if (suffixstr != NULL && STRPREFIX(suffixstr, "be"))
|
||||
ia64_be = 1;
|
||||
} else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) {
|
||||
} else if (STRPREFIX(archstr, "powerpc64")) {
|
||||
arch = VIR_ARCH_PPC64;
|
||||
} else if (STRPREFIX(&token[subs[2].rm_so], "armv7l")) {
|
||||
} else if (STRPREFIX(archstr, "armv7l")) {
|
||||
arch = VIR_ARCH_ARMV7L;
|
||||
} else if (STRPREFIX(&token[subs[2].rm_so], "aarch64")) {
|
||||
} else if (STRPREFIX(archstr, "aarch64")) {
|
||||
arch = VIR_ARCH_AARCH64;
|
||||
} else {
|
||||
continue;
|
||||
@ -515,7 +512,6 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
regfree(®ex);
|
||||
|
||||
for (i = 0; i < nr_guest_archs; ++i) {
|
||||
virCapsGuestPtr guest;
|
||||
|
Loading…
x
Reference in New Issue
Block a user